linux - What happens when a signal is received while already in a signal handler? -
i have parent process spanning several child processes. want know when child process exits registering sigchld
signal handler.
the question is, happens if sigchld
(or other signal) received, while parent process in signal handler?
i can think of following outcomes:
- the signal ignored
- the signal queued, , processed current handler returns
- the current handler in turn interrupted, main program
which 1 correct?
in concrete example (the same signal being received), signal delivered after signal handler has finished (so bullet point #2 correct). note, however, may "lose" signals.
the reason while signal being inside handler, blocked. blocked signals set pending, not queued. term "pending" means operating system remembers there signal waiting delivered @ next opportunity, , "not queued" means setting flag somewhere, not keeping exact record of how many signals have arrived.
thus, may receive 2 or 3 (or 10) more sigchld
while in handler, see 1 (so in cases, bullet point #1 can correct, too).
note several flags can pass sigaction
can affect default behaviour, such sa_nodefer
(prevents blocking signal) , sa_nocldwait
(may not generate signal @ on systems).
now of course, if receive different type of signal, there's no guarantee won't interrupt handler. reason, 1 preferrably doesn't use non signal safe functions.
Comments
Post a Comment