note 94659 added to function.pcntl-alarm
| From: | wookie at osu1 dot php dot net | Date: | Tue, 17 Nov 2009 11:51:03 +0000 |
| Subject: | note 94659 added to function.pcntl-alarm | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162973@lists.php.net to get a copy of this message | ||
I replaced the for(;;) in the code posted by 'j at ukr-info dot net' with the following 3
sections testing after each:
for(;;) {
print "sleep 10\n";
sleep (10);
}
for(;;) {
print "sleep 10\n";
exec( 'sleep 10' );
}
for(;;) {
print "sleep 10\n";
pcntl_exec('/bin/sleep', array(10));
}
The first loop works as I expect. Every 5 seconds the alarm is fired, which causes the sleep to
return and the loop starts again. So every 5 seconds you see:
sleep 10
Caught SIGALRM
The second loop is different. In this loop the sleep in the exec happens, then when it returns the
alarm is fired. So every 10 seconds you see:
sleep 10
Caught SIGALRM
The 3rd loop is different again. It waits 5 seconds then exits the loop and stops. The output is:
sleep 10
Alarm clock
The first 2 examples I think I can explain. In the first example the process thread is running the
sleep command when the alarm fires. This moves the program pointer to the alarm code and then
returns to the loop after the sleep. The second example, the exec blocks this thread so that even
though the alarm has fired it will not execute the alarm code till after the return of the exec
command.
The last version I have no idea about. Where does it get Alarm clock from?
----
Server IP: 69.147.83.197
Probable Submitter: 91.212.94.19
----
Manual Page -- http://www.php.net/manual/en/function.pcntl-alarm.php
Edit -- https://master.php.net/note/edit/94659
Del: integrated -- https://master.php.net/note/delete/94659/integrated
Del: useless -- https://master.php.net/note/delete/94659/useless
Del: bad code -- https://master.php.net/note/delete/94659/bad+code
Del: spam -- https://master.php.net/note/delete/94659/spam
Del: non-english -- https://master.php.net/note/delete/94659/non-english
Del: in docs -- https://master.php.net/note/delete/94659/in+docs
Del: other reasons-- https://master.php.net/note/delete/94659
Reject -- https://master.php.net/note/reject/94659
Search -- https://master.php.net/manage/user-notes.php