Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing a daemon

Status
Not open for further replies.

woche

Programmer
Jan 16, 2002
25
CH
hello
i'm trying to write a shell script which does something in a loop, ignores some signals (HUP,...) -etc. -> make it behave somewhat like a daemon. my problem: how can i communicate with my "daemon"? after having started the script as a background process, i would like to log off, log on some time later and send it a signal like "stop" to make it stop. how is this possible? "where" do i have to send the signal to?
i know of the possibility of killing processes with their PID, but i want to do it in another way.

thx for your help
woche
 
the problem is the communication.
one possible (very dirty way) is a common file on disk
exemple
the deamon runs and check for his comm-file periodically
you (user) cann write or remove the comm-file
if the deamon cannot stat the comm-file, or find in it a command,
exits or execute the cmd.
i don't like this, but if you don't known c or perl it's the only way.
shared memory (shmem) or interprocess-communication (ipcs) are better.
see man pages.
------------ jamisar
Einfachheit ist das Resultat der Reife. (Friedrich Schiller)
Simplicity is the fruit of maturity.
 
Jamisar is correct about the "lock-file" ,pid file
idea. The problem is that you want to identify the
"daemonized" script in another way and then send it
a signal to fire a trap action, is that right?

The utility you need is fuser(man fuser).
As far as the idea goes it's sort of complex for the
shell, don't you think? You could use expect and it's
huge arsenal of tools for this.:
fork, interact, indirect spawn_ids, fifo's,etc..
 
okay, i get the picture. i guess i stick to writing the thing in shell and havin cron execute the script periodically. say i wanted to run the script every five minutes, stop it from running when an error occurred and not execute the script between 4 and 6 a.m every day. can i do that in cron?

thx!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top