|
- #!/usr/bin/perl -W
- $flag = 1;
- if (!defined($kidpid = fork())) {
- # fork returned undef, so failed
- die "cannot fork: $!";
- } elsif ($kidpid == 0) {
- for($i=0;$i<3;$i++)
- {
- print "I am child\n";
- sleep(3);
- }
- } else {
- # fork returned neither 0 nor undef,
- # so this branch is the parent
- foreach $a (keys %SIG)
- {
- print "$a.............$SIG{$a}\n";
- }
- print "Parent...........\n";
- }
- $SIG{'CHLD'} = 'my_sigint_catcher';
- while($flag)
- {
- print "Waiting........\n";
- sleep(1);
- }
- sub my_sigint_catcher {
- print "子进程推出\n";
- waitpid($kidpid, 0);
- $flag = 0; # set a flag
- }
复制代码
我的操作系统是redhat
接收不到 CHLD 信号
请指教!! |
|