Coder Perfect

In Linux, there is a difference between a cronjob and a daemon. When should you utilize it? [closed]

Problem

Making a process daemonized has advantages, as it removes it from the terminal. However, the same thing may be accomplished with a cron job. [Please correct me if I’m wrong.]

What is the best criterion for determining whether to utilize a cronjob or a daemon process in different scenarios?

Asked by Whoami

Solution #1

In general, you should start a daemon if your task has to execute more than a few times each hour (maybe 10 minutes).

The following are the advantages of having a daemon that is always running:

BUT

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.

Answered by MarkR

Solution #2

The execution time frame distinguishes a cronjob from a daemon.

A cronjob is a process that runs on a regular basis. A cronjob could be a script that periodically deletes the contents of a temporary folder, or a software that delivers push alerts to a group of devices every day at 9.00 a.m.

A daemon, on the other hand, is a process that runs independently of any user and does not restart when it expires.

Answered by tomahh

Solution #3

You’ll need to operate a daemon if you need a service that is always available to others. Because the daemon must be able to communicate with the outside world on a continuous basis (for example, by listening on a socket or TCP port), and it must be written to handle each job cleanly without leaking or even locking up resources for an extended period of time, this is a fairly difficult programming task.

In contrast, if you have a specific job whose description can be specified ahead of time, which can operate automatically without further information, and is self-contained, a cron job that does the work on a regular basis may be sufficient. Because you only need a software that runs once for a certain period and then quits, this is considerably easier to build for.

A daemon, in a nutshell, is a single process that runs indefinitely. A cron job is a technique for launching a new, short-lived process on a regular basis.

Answered by Kerrek SB

Solution #4

By storing state, postponing disk writes, or participating in protracted sessions with a client, a daemon can take use of its longevity.

Memory leaks must be avoided in a daemon, as they are likely to build over time and cause problems.

Answered by Paul Beckingham

Post is based on https://stackoverflow.com/questions/12975495/cronjob-vs-daemon-in-linux-when-to-use