note 94659 deleted from function.pcntl-alarm by danbrown

From: Date: Tue, 17 Nov 2009 15:26:01 +0000
Subject: note 94659 deleted from function.pcntl-alarm by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162984@lists.php.net to get a copy of this message
Note Submitter: wookie ---- 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?

« previous php.notes (#162984) next »