Link to home
Start Free TrialLog in
Avatar of Jitu
Jitu

asked on

Daemon ?

How do i write a program that runs as a Daemon ?

Basically i want to achieve this :
I want to invoke a carry out a certain activity (liking invoking a certain application) based on time. That is, i schedule some activities for some time in future. Now, my appln. should continuosly check for time and if it is time to carry out that activity, simply do that, and continue running.

I guess, i must write a program that runs in background as a Daemon.

What language has to be used...Shell Script/C ?

How do i do this ?
Any available code ...
or info. on where i can find help on this would be helpful.

Thx.

Avatar of sereda
sereda

You should use C.
man fork
man setsid
man exit
man chdir

scenario:
1. fork.
parent:
  2. sleep a while;
  3. exit;
child:
  2. chdir "/";
  3. setsid ()
  4. infinite loop

If you want a code example, i think you should increate point cost ;)
What's wrong with "cron"? What you have described is all done by cron, plus cron has security features and is started when the system boots. You program would have to be restarted if the system was rebooted, plus there would be an additional CPU overhead.
Avatar of Jitu

ASKER

tfewster >
I am new to UNIX. I have no idea what is "cron" and how to use it...
Can u give some input or sample code..Thx.
$ crontab -e
-- your EDITOR appears
-- enter there:
* * * * * echo "Minute tick" > /dev/console
--- save file
===

Here is an example.
You will receive a message on console once per minute.

to get more information, run
   man crontab
   man cron


ASKER CERTIFIED SOLUTION
Avatar of tfewster
tfewster
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Come on Jitu - As an expert yourself, you must know how frustrating it is to wait for someone to accept an answer!