Please share with me a better method of identifying that a program is already running from that program.
My current thoughts are a system call to "ps aux | grep programname" but then what?
Please share with me a better method of identifying that a program is already running from that program.
My current thoughts are a system call to "ps aux | grep programname" but then what?
Some men annoy a lad called waitpid with their concerns.
i dont believe in competition in da field of cboard posts, u see, i believe in a collection of posts each 2 be admired for der own personal statement. when in doubt, ask Willy!
This should be in the Linux thread - You will get better answers there
Fact - Beethoven wrote his first symphony in C
and what does one do if one does not know the pid of the process one is waiting for?
I know the name of the program concerned but not its pid so I cannot see waitpid solving the issue.
Last edited by straygrey; 11-17-2013 at 06:27 AM. Reason: clarity
The usual way is to create a lock file in a known location (say /tmp), with a name something like
.lock_my_program_name.pid
Each time you run the program, the first thing it does is try to find a file matching .lock_my_program_name.
If one is found, then check whether the .pid part of the name matches a running process ID, and whether that process ID is really another instance of your program.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Thank you Salem. I will do just that.