10-29-05 10:51 PM
seema_coma@yahoo.co.in writes:
> Hi All I am new to unix programming. I have a
> problem, I am using fork and in the child
> process I am doing some what like this,
>
> if ((pid = fork()) == 0) {
> execvp(path, regdArgv);/*execute "my executable"*/
> }
>
> which will invoke an executable. But i just
> want to do some thing like this,
> if ((pid = fork()) == 0) {
> if (/my executable is already running*/){
> exit(0);
> }
> else{
> execvp(path, regdArgv);
> }
>
> }
>
> Can some body explain how to CHECK that executable
> is already running ?
Have the executable create a file somewhere (on a *local* file
system), and get a lock on it. It can simply be a zero length file,
the important thing is that it's locked.
When the program starts up, have it try to get a lock on the file. If
it can't get a lock, then an instance of the program is already
running.
Joe
--
Gort, klatu barada nikto
[ Post a follow-up to this message ]
|