#!/usr/bin/perl if (my $pid = fork()) { # kill process group after timeout sleep 3; show_procs(); kill -9, $pid; # negative signal number kills group wait; print "killed children\n"; show_procs(); # show remaining processes # ... } elsif (defined $pid) { setpgrp; # create new process group # run something (consisting of several processes) that takes a while exec 'find / | grep foo'; } else { die "couldn't fork"; } sub show_procs { system "ps Tf -o pid,ppid,pgrp,sid,cmd"; } __END__ $ ./841709.pl PID PPID PGRP SID CMD 12046 12044 12046 12046 bash -rcfile .bashrc 3881 12046 3881 12046 \_ /usr/bin/perl ./841709.pl 3882 3881 3882 12046 \_ sh -c find / | grep foo 3883 3882 3882 12046 | \_ find / 3884 3882 3882 12046 | \_ grep foo 3885 3881 3881 12046 \_ ps Tf -o pid,ppid,pgrp,sid,cmd killed children PID PPID PGRP SID CMD 12046 12044 12046 12046 bash -rcfile .bashrc 3881 12046 3881 12046 \_ /usr/bin/perl ./841709.pl 3886 3881 3881 12046 \_ ps Tf -o pid,ppid,pgrp,sid,cmd