Back to index

php5  5.3.10
test-pcntl.php
Go to the documentation of this file.
00001 #!../../php -q
00002 <?
00003 
00004 declare(ticks=1);
00005 
00006 function alarm_handle($signal){
00007         if ($signal==SIGALRM) print "Child: Caught SIGALRM!!!\n";
00008 }
00009 
00010 function usr1_handle($signal){
00011        if ($signal==SIGUSR1) print "Child: Caught SIGUSR1!!!\n";
00012 }
00013 
00014 print "This test will demonstrate a fork followed by ipc via signals.\n";
00015 
00016 $pid=pcntl_fork();
00017 if ($pid==0) {
00018        pcntl_signal(SIGUSR1, "usr1_handle");
00019        pcntl_signal(SIGALRM, "alarm_handle");
00020        print "Child: Waiting for alarm.....\n";
00021        sleep(100);
00022        print "Child: Waiting for usr1......\n";
00023        sleep(100);
00024        print "Child: Resetting Alarm handler to Ignore....\n";
00025        pcntl_signal(SIGALRM, SIG_IGN);
00026        print "Child: sleeping for 10 seconds....\n";
00027        sleep(10);
00028        print "Done\n";
00029 } else {
00030        print "Parent: Waiting 10 seconds....\n";
00031        sleep(10);
00032        print "Parent: Sending SIGALRM to Child\n";
00033        posix_kill($pid,SIGALRM);
00034        sleep(1);
00035        print "Parent: Senging SIGUSR1 to Child\n";
00036        posix_kill($pid,SIGUSR1);
00037        sleep(2);
00038        print "Parent: Sending SIGALRM to Child\n";
00039        pcntl_waitpid($pid, &$status, $options);
00040 }