note 49663 added to function.pcntl-signal
| From: | codeslinger at compsalot dot com | Date: | Fri, 04 Feb 2005 05:23:16 +0000 |
| Subject: | note 49663 added to function.pcntl-signal | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84499@lists.php.net to get a copy of this message | ||
I ran into an interesting problem. CLI 4.3.10 Linux
The parent forked a child. The child did a bunch of stuff, and when it was done it sent SIGUSR1 to
the parent and immediately exited.
Result:
The child turned into a zombie process waiting for the parent to harvest it, as it should.
But the parent was unable to harvest the child because it was receiving an endless barrage of
SIGUSR1s. In fact, it logged over 200000 before I shut it down (SIGKILL). The parent was not able
to do anything else (respond to other events) during that time.
No, it wasn't a bug in my child code. Apparently, after sending a signal there is some
"behind the covers" work that needs to occur to acknowledge signal completion, and when
you exit immediately it is not able to happen, so the system just keeps trying.
Solution: I introduced a small delay in the child, after sending the signal, and before exiting.
No more Sig loops...
----------
P.S. With respect to the note below. The whole point of the sleep function is to enable the
processing of other events. So, yes, your non-renterent code, will suddenly get re-entered when you
do a sleep, because you have just handed off control to the next pending event.
Ignoring the signal is only an option if the signal is unimportant to your program.... The better
way to approach it, is to not do lengthy processing inside of the signal event. Instead set a
global flag and get the heck out of there as fast as possible. Allow another part of your program
to check the flag and do the processing outside of the signal event. Usually your program is in
some kind of loop when it is receiving signals, so checking a flag regularly shouldn't be a
problem.
----
Manual Page -- http://www.php.net/manual/en/function.pcntl-signal.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49663
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49663&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49663&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49663&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49663&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49663&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49663&report=yes
Search -- http://master.php.net/manage/user-notes.php