Re: [LIP] check instance of a running application

Binand Sethumadhavan <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Message-ID <[email protected]>
On Wed, Dec 24, 2003 at 04:45:43AM -0800, Ram wrote:
> For checking whether app is still running , I tried by
>  writing the  PID value to a file and later checked
> whether it exists or not. is there any other way to do
> this....

Your method is fine. On startup, log the PID in a file somewhere. To
check if the application is running or not, use kill().

from kill(2) manpage:

       If sig is 0, then no signal is sent, but error checking is still
       performed.

ie, something like:

if (kill (pid, 0) == 0) {
	printf ("PID %d is running\n", pid);
} else {
	if (errno == ESRCH) {
		printf ("PID %d is not running\n", pid);
	}
}

Binand

-- 
Linux - It is now safe to power ON your computer.


-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.