cronjob vs daemon in linux. When to use? [closed]

In general, if your task needs to run more than a few times per hour (maybe <10 minutes) you probably want to run a daemon.

A daemon which is always running, has the following benefits:

  • It can run at frequencies greater than 1 per minute
  • It can remember state from its previous run more easily, which makes programming simpler (if you need to remember state) and can improve efficiency in some cases
  • On an infrastructure with many hosts, it does not cause a “stampedeing herd” effect
  • Multiple invocations can be avoided more easily (perhaps?)

BUT

  • If it quits (e.g. following an error), it won’t automatically be restarted unless you implemented that feature
  • It uses memory even when not doing anything useful
  • Memory leaks are more of a problem.

In general, robustness favours “cron”, and performance favours a daemon. But there is a lot of overlap (where either would be ok) and counter-examples. It depends on your exact scenario.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)