Use Cron or Daemon?


What is the difference between a cron job and a daemon?

If you need a service that it permanently available to others, then you need to run a daemon. If you have a specific job whose description can be determined well enough in advance, and which can act automatically without further information, and is self-contained, then it may be entirely sufficient to have a cron job that runs the task periodically.

A daemon is complicated, and needs to be written to handle each job cleanly without leaking or even locking up resources for a long time. Cron is much simpler to design, since it only need a program that runs once for a limited time and then quits.

In a nutshell: A daemon is a single process that runs forever. A cron job is a mechanism to start a new, short-lived process periodically.

If you have a programme that took an unpredictable amount time to complete a task, use daemon. Daemon on run the process when the previous process has ended whereas cron allows overlap. There are processes that damages the system if the process runs concurrently so for this use case run daemon.

I will be sharing how to daemonise php script using upstart on the 30th January 2014 in Singapore. Stay tuned.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s