7

I am having trouble finding an answer to this question thorough google:

How exatly does CRON in ubuntu execute jobs?

Does it spawn each new job in its own process?

Say i have two cron jobs:

@reboot /some/really/slow/job
* * * * * /some/quick/job

Will these jobs run side by side, or will the first one block the second until its done?

Secondly, does Cron affect redirects? Say i have a script which contains something like

rsync --verbose /from /to &>>rsynclog.log

Will the log file be written when called from CRON? Or does it end up somewhere else?

1 Answer 1

7

This answer is for ubuntu. Other linux / unix operating systems may vary slighty.

Every minute the cron daemon reads all the crontab files and loads them into memory. For each cron entry which is to be run (determined by the crontab time fields) cron forks a copy of itself.

The forked cron child process then executes a new shell (typically /bin/sh but this can be overridden) to execute the crontab command. cron itself only forks the child processes that manage the jobs. So the cron entries are run concurrently - if one job takes an hour for example, it will not impact on the execution of any other cron jobs.

Redirection should work as normal and the output file will be written to the $HOME directory of the user who owns the crontab. It some cases it is worth providing the full path to commands and redirected files to avoid issues with PATH and HOME settings.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .