Reputation: 2496
How to check that another instance of program already running under UNIX system? And exit()
if so.
I'm already use file
with pid
on it when the process start. Then I check pid
that its exists. BUT time to time program run on unexpected behavior and I have tons of copies of the program running.
Upvotes: 1
Views: 2307
Reputation: 166
If you are writing pids to a file then you should serialise access to the file with flock.
Upvotes: 1
Reputation: 1
Use an appropriate synchronization mechanism (e.g. a process shared semaphore), to prevent starting your program twice.
Upvotes: 1