#!/usr/bin/perl use strict; use warnings; my $cmd = qq{nohup ./perl.pl &}; my $pid = fork; die 'fork failed' unless defined $pid; if ($pid) { print STDERR "parent pid=$$ child pid=$pid\n"; wait; my $sid = getppid; system "ps f -s $sid -o pid,ppid,pgrp,sid,cmd"; } else { print STDERR "child pid=$$ \$pid=$pid\n"; setpgrp; exec $cmd or die "Bad exec: $!"; } #### #!/usr/bin/perl system 'sleep 1'; #### $ ./813283.pl child pid=31851 $pid=0 parent pid=31850 child pid=31851 PID PPID PGRP SID CMD 18307 18305 18307 18307 bash -rcfile .bashrc 31850 18307 31850 18307 \_ /usr/bin/perl ./813283.pl 31853 31850 31850 18307 \_ ps f -s 18307 -o pid,ppid,pgrp,sid,cmd 31852 1 31851 18307 /usr/bin/perl ./perl.pl 31854 31852 31851 18307 \_ sleep 1