File: sigchld_handler.pl

package info (click to toggle)
libmojo-ioloop-readwriteprocess-perl 1.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 540 kB
  • sloc: perl: 4,655; sh: 101; makefile: 2
file content (20 lines) | stat: -rwxr-xr-x 394 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/perl
use warnings;
use strict;
use Time::HiRes 'sleep';

my $collected_pid = -1;
$SIG{CHLD} = sub {
  $collected_pid = waitpid(-1, 0);
  print "SIG_CHLD $collected_pid exit:" . ($? >> 8) . "\n";
};

my $pid = fork();
if ($pid == 0) {
  print "I'm the child $$\n";
  exit 0;
}
print "Forked child is $pid\n";
sleep 0.1 while ($collected_pid != $pid);
print "Exit graceful\n";
exit 0;