6

What is the difference between cron and lauchd? I have always used cron, but I have recently heard that launchd is better. Why? In what ways is cron better? In what ways is launchd better?

5

launchd does a lot more than cron. In addition to running programs at certain times, it can also run them based on other triggers: incoming network connection, when a file is added to a certain folder, etc. It can also relaunch a program if it crashes.

If you're interested in it specifically as a replacement for cron, the main difference is how it handles being asleep or shut down when a job is scheduled to run. In this case, cron simply doesn't run the job, but launchd will notice that a scheduled run has been missed, and run it at the next opportunity (although if it's missed multiple scheduled runs, it'll only run it once).

Edit: I should also point out some things that cron can do that launchd cannot: automatic emailing of failure reports (you'd have to write a wrapper script to do this with launchd) and user-defined jobs that run even when the user isn't logged in (a user can define launchd items in ~/Library/LaunchAgents, but they only run inside a login session).

2
  • Awesome! Switching to launchd! – daviesgeek Oct 1 '11 at 14:43
  • 1
    At least according to the Daemons and Services Programming Guide, running missed jobs later only applies to jobs scheduled during sleep (not when shut down) and by StartCalendarInterval. – Lri Apr 6 '13 at 4:14

You must log in to answer this question.

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