How to implement singleton in shell script
In kornshell, `basename $0` gives me the name of the current script. How would I exploit $$ or $PPID to implement the singleton pattern of only having one script named `basename $0` executed on this server by any user? ps -ef|grep `basename $0` This will show me all processes which are running that have the name of the currently running script. I need a script which can abort when a thread which is not $$ is running the script named `basename $0`. To provide a race-free mutex, flock is your friend. If you aren't on Linux -- where it's provided by util-linux -- a portable version is available.