Skip to content

Instantly share code, notes, and snippets.

@exodist
Created September 29, 2019 04:13
Show Gist options
  • Select an option

  • Save exodist/5c007d37ebbb939a3e558b67924df39c to your computer and use it in GitHub Desktop.

Select an option

Save exodist/5c007d37ebbb939a3e558b67924df39c to your computer and use it in GitHub Desktop.
PID: 508335 (506711)
Kill: 0
A: 508335 (506711)
B: 508335 (508335)
wait 0: -1
Kill: 1
child exits 508335 (508335)
wait 0: -1
Kill: 1
got sigchild
wait 508335: 0
Kill: 1
wait -1: -1
Kill: 1
wait -1: -1
Kill: 1
Deep child exits 508336 (508335)
wait -1: -1
Kill: 0
wait -1: -1
Kill: 0
wait -1: -1
Kill: 0
wait -1: -1
Kill: 0
wait -1: -1
use strict;
use warnings;
use POSIX;
$SIG{CHLD} = sub { print "got sigchild\n"};
my $pid = fork;
if ($pid) {
print "PID: $pid (" . getpgrp . ")\n";
for (1 .. 10) {
my $ok = kill(0, -$pid);
print "Kill: $ok\n";
sleep 1;
my $out = waitpid(-$pid, WNOHANG);
print "wait $out: $?\n";
}
exit 0;
}
print "A: $$ (" . getpgrp . ")\n";
setpgrp(0, 0);
print "B: $$ (" . getpgrp . ")\n";
$pid = fork();
if ($pid) {
sleep 2;
print "child exits $$ (" . getpgrp . ")\n";
exit 0;
}
sleep 5;
print "Deep child exits $$ (" . getpgrp . ")\n";
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment