Re: Linux: Question on sigprocmask

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




>>
>> Any other suggestions ? 
>>

hi Sharath,

what i have done in the past and seems to work quite well is
to create a dedicated thread to handle signals.

all the other app threads should block the signals 
you want to catch.  this can be done in main(), prior
to creating any threads with pthread_sigmask(SIG_BLOCK,...

this way any pthreads created after calling pthread_sigmask
will inherit the same signal mask.  this would be the body
of the dedicated signal catching thread:

    for EVER
    {
        /*
         * Wait here until a blocked signal is posted.
         */
        if (sigwait(&job->blocked_signals, &signal_nmbr) == 0)
            semop(...)
        else
            error(...) 
    }

hope this helps ,

peace,

dan

> Hi,
> 
> This is a problem on signal handling.  I have an multi-threaded application
> which works find on AIX but am facing problems on Linux.   I was browsing
> though the web and thought this might be the right place to ask the
> question.
> Could you please advice ?
> 
> I am executing a semop call in a function which is called from a signal
> handler.  Since semop call returns an error code of EINTR when it is
> interrupted by a signal, i need to mask the signals at the starting of this
> function and unmask it at the end of the function.
> 
> On Aix i use sigthreadmask to block the signals in the thread which calls
> this function and everything works fine.
> 
> On Linux since there is no sigthreadmask, i have to use either
> pthread_sigmask and sigprocmask.
> 
> If i use pthread_sigmask, it masks the signals for the current thread.  so
> if i issue a kill -2 to this process, the semop call doesn't fail.  However
> if  i issue 2 signals at a time (kill -3 <pid> ; kill -2 <pid>) the semop
> call fails ( the reason i feel is that some other thread which is not
> masking this signal gets it) (since threads implementation on linux is
> different than aix).
> 
> This problem doesn't get solved even if i use sigprocmask.  I am using
> Red Hat Linux release 7.2 (Enigma)
> Kernel 2.4.7-10 on an i686
> 
> Is sigprocmask not working as designed ?  Is there any other call which can
> be used ?  Any other suggestions ?
> 
> 
> 
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 
> 
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux