40m QIL Cryo_Lab CTN SUS_Lab TCS_Lab OMC_Lab CRIME_Lab FEA ENG_Labs OptContFac Mariner WBEEShop
  40m Log  Not logged in ELOG logo
Message ID: 187     Entry time: Mon Dec 10 20:35:59 2007
Author: tobin 
Type: Configuration 
Category: Computer Scripts / Programs 
Subject: autolocking scripts 
I added this tidbit of csh code to the MZ autolocker to prevent multiple copies from running (on one computer):
if (`pgrep lockMZ | wc -l` > 1) then
   echo lockMZ is already running! 
   exit
endif
Similarly, here's some bash code that does something similar; I'll add it to the other autolocker scripts:
if                                                                                                                       
  pgrep `basename $0` | grep -v $$ > /dev/null                                                                           
then                                                                                                                     
  echo Another copy of this program is already running.  Exiting!                                                        
  exit 1                                                                                                                 
fi
This code searches for all processes with the same name as this script ($0) and then use grep to exclude (-v) the current process ID ($$).
ELOG V3.1.3-