use strict; use warnings; my $CMD = '/home/blah/my_process'; my $SLEEP_TIME = 1; # check to see if it is running every 5 seconds while(1) { my @pid_array = `ps -ef | grep /home/blah/my_process`; my $pid_count = scalar(@pid_array); if ($pid_count == 1) { # It isn't running, that 1 is for grep. more than one tells you the process is alive. system "$CMD"; # run it } elsif ($pid_count > 2) { # There is more than one instance running. # Do appropriate stuff print "many instances are running"; } sleep $SLEEP_TIME;