my $progname = 'emacs'; my $label = "_by_" . $$; my $proglabel = $progname . $label; my @args = ( $0 ); if ( my $pid = fork ) { # this is parent code # pause, then zap the child sleep 10; my @lines = grep{ m/$label/ } qx{ ps axw }; my @pids = map{ ( split " ", $_ )[0] } @lines; foreach my $pid ( @pids ) { my $status = kill 1, $pid; ($DEBUG) && print STDERR "Tried to kill (1) pid $pid, status: $status \n"; } } else { # this is child code die "cannot fork: $!" unless defined $pid; exec { $progname } ( $proglabel, @args ); }