ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Hi all, I have a new programming question.
I am writing my personal daemon in C language.
How can I know if my program (daemon) is running?
( with C language, and not with shell )
For example, I try:
#./my program
Exist it a system call that I can use within myprogram to know if istance of myprogram is running?
Oh, I think I get it now. You want to know whether a prior instance of the daemon was already running? Lock files are commonly used for this purpose. No matter what scheme you use, the tricky part is making sure the 'flag', of what ever sort you use, always gets cleared when the daemon exits. If it doesn't, any subsequent attempt to restart the process will fail.
--- rod.
In the your case, the mere presence of the entity is enough to indicate that an instance of the daemon already exists. The entity can be a file, a message queue, shared memory segment, or anything else that can be created and mutually located by arbitrary processes.
--- rod.
there is no definitive way to do it.
lock files are the simplest method and OK ish.
if it's a network server maybe you could have a method of poking it to see if it's alive.
the bottom line is these computer thingies still need us monkeys for some jobs.
when you solve this problem you will be helping them on the road to phasing us out
Last edited by bigearsbilly; 06-18-2007 at 03:38 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.