A solution that does not require additional tools would be prefered.
Almost like nsg's answer: use a lock directory. Directory creation is atomic under linu and unix and *BSD and a lot of other OSes.
You can put the PID of the locking sh into a file in the lock directory for debugging purposes, but don't fall into the trap of thinking you can check that PID to see if the locking process still executes. Lots of race conditions lie down that path. | |||||||||||
feedback
|
I would use a lock file, as mentioned by Marco
| |||||||||||||||
feedback
|
If you want to make sure that only one instance of your script is running take a look at: Lock your script (against parallel run) Otherwise you can check Supplement: actually i thought of doing it like this:
this ensures that only the process with the lowest | |||||||
feedback
|
This may be too simplistic, please correct me if I'm wrong. Isn't a simple
| |||
feedback
|
ln -s my.pid .lock
will claim the lock (followed byecho $$ > my.pid
) and on failure can check whether the PID stored in.lock
is really an active instance of the script – Tobias Kienzler Sep 18 at 15:22