Tuesday, July 26, 2011

Singleton bash script

Sometimes it's important to make sure only one copy of a shell script runs at any given time. Here's an elegant way to find and kill any other processes running as the same name as your script:
kill $(pidof -x -o '%PPID' $0) >/dev/null 2>/dev/null

2 comments:

Anonymous said...

Is there a solution without the use of "pidof" command?
In cygwin unfortunately it is not present...

Bacon Recipes said...

Hi thhanks for posting this