exec() will not return control to PHP to "listen" to SIGs until it is done. get testing2.php to background itself or tack " &" on to the end of the exec command or... On Wed, May 23, 2007 6:59 am, lists@xxxxxxxxxxx wrote: > Hi, > > I have this script testing.php that I run on a Linux machine thru the > command line. In the end of the file you see two cases. One where it > is just having a while(true) loop doing nothing, and the other calling > an other script that is doing nothing but doesn't exit. When I send > SIGTERM for the first case it does what it is supposed to do, but when > sending SIGTERM to the other case it doesn't work. > > Might it be so that the signals cannot be handled if the script is > busy creating its own process or similar? Because when executing it > with case two doesn't leave the exec() part until the other script > exits, and it will never exits. > > I try to send the signal with: > # kill -s SIGTERM 24574 > > The "ps -ef | grep testing.php | grep -v grep" looks like this as > example: > 500 24574 1 0 13:50 ? 00:00:00 /usr/bin/php > ./testing.php > > Best regards, > Peter Lauri > > Code: > > +++++++++++++++++++++++++++++++++++++++++++++++++++++ > > #!/usr/bin/php > <?php > > declare(ticks = 1); > > $pid = pcntl_fork(); > if ($pid == -1) { > die("could not fork"); > } else if ($pid) { > exit(); // we are the parent > } else { > // we are the child > } > > // detatch from the controlling terminal > if (!posix_setsid()) { > die("could not detach from terminal"); > } > > function sig_handle($signo) { > switch($signo) { > case SIGTERM: > echo "I got the SIGTERM signal:".$signo."\n"; > break; > case SIGCHLD: > echo "I got the SIGCHLD signal:".$signo."\n"; > break; > case SIGINT: > echo "I got the SIGINT signal:".$signo."\n"; > break; > } > } > > pcntl_signal(SIGTERM, "sig_handle"); > pcntl_signal(SIGCHLD, "sig_handle"); > pcntl_signal(SIGINT, "sig_handle"); > > //Case 1 with just a while loop is working > //while(true) { > // > //} > > //Case 2 when executing the script testing2.php that also do a > //infinite while loop does not work > //exec("./testing2.php"); > > ?> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php