3

If I add 5 jobs in my crontab, do they execute asynchronously in parallel ? Two of my jobs may take 10 minutes to complete and I want to know if I need to run them in the background (by adding the & at the end of the command).

Bon Ami
  • 893

2 Answers2

5

crontab entries are processed independently, so yes, the jobs are run asynchronously, in parallel. You don't need to background them.

If you ever need to synchronise jobs, check out the techniques mentioned in Can a crontab job run concurrently with itself?.

Stephen Kitt
  • 434,908
0

The exact sequence in which jobs are executed will depend on the implementation of your systems' crond. What is your OS? If you have cronjob in a crontab:

Job 1
Job 2
Job 3

In Debian Job1 will start, without waiting to finish Job 2, etc.
In Debian and Ubuntu derivatives it is top-bottom
In FreeBSD it is bottom-top

If your cronjobs are in /etc/cron.hourly(or daily/monthly/weekly) - then the script that runs them does it sequently, not in paralel. (a script loops though them and waits for each to finish)

EDIT Add two different cronjobs (here I assume you have syslog configured)
* * * * * ls /etc/
* * * * * echo "whatever
tail -f /var/log/cron