The difference between cron and lauchd

cronlaunchd

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?

Best Answer

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).