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.


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

1. fork.
  2. sleep a while;
  3. exit;
  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.
JituAuthor Commented:
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.
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

$ 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

Well said, sereda. Mind if I add some background & tips?

Jitu, cron is the standard Unix scheduler for jobs that you want to run repeatedly: You can specify the start time by the minute, hour, day of week or day of month that you want the job to run. Getting this right needs a bit of practice, so start with seredas example and try different start times.  

Each user has their own "crontab" file, a table of jobs that they want to run, each with it's own start time (as specified above).

You can redirect the output (and any error messages) from the cron job to a log file, so you can check it in the morning (if you don't redirect output, any output will be mailed to you).

Because cron is run as a top level system process and doesn't use your environment, you have to specify full pathnames, like /usr/bin/lp /home/Jitu/my_file

BTW, if you only want to run the job once (e.g. print a large file overnight) you can use "at start_time command", that is run "command" at the specified time. This is much simpler to use!


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Come on Jitu - As an expert yourself, you must know how frustrating it is to wait for someone to accept an answer!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.