sub ProcessRunning { # If the passed string exists in the current Unix/Linux process list, # then this subroutine returns the lines from a "ps -e" command which # contain that string. These lines will look something like # "26787 pts/1 00:00:00 TestLoop.pl". If more than one running # process line contains that string, each of those lines will be # included in the returned value. Since this is Perl, these # returned values can be treated as TRUE if desired. # Make sure to specify a string that will uniquely locate the # processes of interest. Alternatively, the returned value could then # be further examined for other analysis. # # If the string does NOT exist, an empty value is returned, which # can be treated as FALSE. # # Sample usages: # exit if &ProcessRunning($myProcess); # OR # &ProcessRunning($myProcess) and die # "Another copy of process $myProcess is already running\n"; # OR # $result = &ProcessRunning($myProcess); # Examine $result for # further processing return 0 unless (`ps -e | grep @_ | grep -v grep`); } # end sub ProcessRunning