to find current running process

Hi All,

The scenario is like this:

There is a process say "A" which create a child process say "B" if some condition is true and process "A" terminates. "B" invokes some C program say "C" using 'execl' function. The job of program "C" is to keep polling the server until the server will be up.

Now, the requirement is, when "A" is called next time, it should check is there any process is running for program "C". If yes then "A" terminates.

My question is: How to find whether the program "C" is running or not in "A" code?

regards,

Ranjeet

Without using root privileges and keeping it simple:

  1. you can call popen to execute a shell command like "ps" to find process "C"
    if there is a clear way to tell from ps output that process "C" is out there.

or

  1. create path/filename that all the programs agree upon, and use it as a lock file.
    When "C" starts it writes something like "Process C is running" to the file and closes it.
    When process "C" exits it removes the line from the file. All process "A" has to do is read the file to see if "C" is running. Or just have C create an empty file and delete the file when C exits. Then A just checks for the exsitence of the file.

try the following
ps -ef | grep "procname"