Skip to content

Instantly share code, notes, and snippets.

@yaotti
Created May 26, 2010 02:13
Show Gist options
  • Save yaotti/413961 to your computer and use it in GitHub Desktop.
Save yaotti/413961 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Linux::Pid qw/getpid getppid/;
my $pid = fork;
if( $pid ){
warn "Parent: " . getpid();
warn "Parent's parent: " . getppid();
exit;
} else{
#sleep 3;
warn "Child: " . getpid();
warn "Parent pid: " . getppid();
}
# Parent: 44361 at - line 8
# Parent's parent: 17147 at - line 9
# Child: 44362 at - line 13
# Parent pid: 44361 at - line 14
### sleep 3をコメントアウト(親が先に死ぬ)
# Parent: 44371 at - line 8
# Parent's parent: 17147 at - line 9
# Child: 44372 at - line 13
# Parent pid: 1 at - line 14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment