xref: /PHP-5.4/ext/pcntl/test-pcntl.php (revision 660afcae)
1#!../../php -q
2<?
3
4declare(ticks=1);
5
6function alarm_handle($signal){
7	 if ($signal==SIGALRM) print "Child: Caught SIGALRM!!!\n";
8}
9
10function usr1_handle($signal){
11	if ($signal==SIGUSR1) print "Child: Caught SIGUSR1!!!\n";
12}
13
14print "This test will demonstrate a fork followed by ipc via signals.\n";
15
16$pid=pcntl_fork();
17if ($pid==0) {
18	pcntl_signal(SIGUSR1, "usr1_handle");
19	pcntl_signal(SIGALRM, "alarm_handle");
20	print "Child: Waiting for alarm.....\n";
21	sleep(100);
22	print "Child: Waiting for usr1......\n";
23	sleep(100);
24	print "Child: Resetting Alarm handler to Ignore....\n";
25	pcntl_signal(SIGALRM, SIG_IGN);
26	print "Child: sleeping for 10 seconds....\n";
27	sleep(10);
28	print "Done\n";
29} else {
30	print "Parent: Waiting 10 seconds....\n";
31	sleep(10);
32	print "Parent: Sending SIGALRM to Child\n";
33	posix_kill($pid,SIGALRM);
34	sleep(1);
35	print "Parent: Senging SIGUSR1 to Child\n";
36	posix_kill($pid,SIGUSR1);
37	sleep(2);
38	print "Parent: Sending SIGALRM to Child\n";
39	pcntl_waitpid($pid, &$status, $options);
40}
41