Re: sigaction system call

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

 



On Monday 15 November 2004 13:20, Russell Miller wrote:
> I'm having a hard time figuring out what the NODEFER flag in
> sigaction actually does.
[...]
> it looks like if SA_NODEFER is not set, then it blocks the signal. 
> Does the signal get moved into the pending signal slot, or does it
> just get blocked? I don't understand.
>
> I also don't understand what happens if SA_NODEFER is set.  I have
> some code (that reaps children) that can get triggered at almost the
> same time.  With SA_NODEFER set, it appears that sometimes the
> handling routine doesn't get allowed to finish if it gets interrupted
> by another signal.

If SA_NODEFER is set, then the single handler can be called while 
executing that single handler (from a previous signal).

> So, an explanation would be appreciated, along with an answer to this
> question:  If I have a SIGCHLD handling routine that is likely to get
> called at the same time, and do NOT set SA_NODEFER, will the SIGCHLD
> signal get deferred until the handling routine gets called, and then
> processed?  Or will the SIGCHLD signal just get lost?  I can't afford
> to have hundreds of zombies sitting around because the "waitpid" call
> never happens.

The sigaction manpage has

       sa_mask gives a mask of signals which should be blocked  during
       execution  of  the  signal handler.  In addition, the signal
       which triggered the handler will be blocked, unless the
       SA_NODEFER or  SA_NOMASK  flags are used.

       SA_NOMASK or SA_NODEFER
                     Do not prevent the signal from being received from
                     within its own signal handler.

This shows what happens if you have signal handlers for both USR1 and 
CHLD.  The two columns are are the difference in USR1 having the 
SA_NODEFER set or not.

SA_NODEFER set				SA_NODEFER not set
---------------------------				---------------------------------
SIGUSR1 sent					SIGUSR1 sent
SIGUSR1 handler called			SIGUSR1 handler called
SIGCHLD sent					SIGCHLD sent
SIGCHLD handler called			SIGCHLD handler called
SIGCHLD hander returns			SIGCHLD handler returns
SIGUSR1 sent					SIGUSR1 sent
SIGUSR1 handler called (again)
SIGUSR1 handler returns
SIGUSR1 handler returns (again)	SIGUSR1 handler returns
								SIGUSR1 handler called
								SIGUSR1 handler returns

If you want to prevent the the CHLD handler from being called while
processing the USR1 signal, then you need to specify that signal in the 
sa_mask field in the struct sigaction when registering the USR1 
handler.

Defered signals (or masked ones) don't get lost, but they don't count 
either.  i.e. if you get N signals of a particular type, you're handler 
will be called M times, where M <= N.


--
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