What is the difference among the various event schedulers for OS X / Darwin?

I'm confused about the differences among the three (that I know of) tools for scheduling running of code on OS X / Darwin:

  • cron
  • launchcd
  • pmset

I understand that cron is largely deprecated, but it is still used by some utilities (like Super Super!, for some reason), and that pmset has the ability to wake the computer to run specific jobs. But I'm not clear what would guide the selection of one over the other in general.

How do these three methods OS scheduling differ (especially on Mavericks, if things are different there), especially in the kids of tasks they are suited to, and how they behave during sleep or hibernation?


Use launchd instead of cron, at, or other legacy UNIX tools for Mac OS X.

pmset

pmset is a built-in command line tool for getting and setting power related values on Mac OS X. One of pmset's abilities is to add and remove entries from the IOPMQueue; the IOPMQueue is the IOKit level queue that allows your Mac to power on and wake up at a specific time. IOPMQueue also supports scheduling of shut downs and restarts.

Arbitrary code can not be scheduled using pmset or through the IOPMQueue.

cron

cron is a stalwart of the task scheduling world. However on Mac OS X, using cron is not recommended. Use launchd.

cron is implemented by checking each minute for tasks that are due. This allows for a powerful and expressive scheduling format but at the cost of needing to wake the processor up every minute.

cron does not know about your Mac sleeping. If a task is due while your Mac is asleep or powered off, the task will not occur. When your Mac powers back on, the task will not be performed because the minute in which it should have run has passed.

There are other tools that build upon cron and can run missed tasks upon waking. None are included by default with Mac OS X.

launchd

launchd (launch daemon) is Apple's system starter, scheduling tool, and process watchdog. launchd is written for the needs of the operating system first and users second. It is a powerful and capable process used to manage or launch almost every other process on your Mac.

launchd is an improvement on cron for scheduling because it does not need to poll to perform tasks. Instead launchd can remain inactive until the moment a task needs performing. In an era of energy aware and mobile computing, this is important.

launchd will not wake a sleeping Mac to perform tasks.

launchd job tickets are property list (plist) files. These files can be edited with a text editor or with a number of third party applications.

launchd is recommended for, and is suitable for, most scheduling situations.

Third Party

There are number of third party scheduling tools available on Mac OS X. They often provide a graphical interface or offer more features than are included in the standard Mac OS X command line tools. The tool I am associated with is Power Manager.


pmset is low level stuff, and doesn't really control running of code specifically, at least not in any direct or intended way. It controls things like turning your Mac on or off at specific times, similar to the way that you can do in System Preferences » Energy Saver. Generally speaking, you shouldn't ever need to use pmset for anything directly.

cron is still there because… well, because Apple hasn't killed it off yet, despite having deprecated it ages ago. I suspect it’s because there are a few old-time Un*x folks still working at Apple who don't want to see it go. But, really, there's no real sense in using that if you can use launchd. IIRC cron jobs do not run if the computer was asleep when it was supposed to run.

launchd is Apple's replacement for cron which adds a lot of flexibility to the scheduling of events on a Mac. This is the way that you should be scheduling events on a Mac. The best way to learn how to use launchd is LaunchControl, which is a US$10 app with no DRM, no license codes, and no restrictions. (The developers rely on the honesty of their users to pay the registration fee if they use the app.) Not only do you get drag-and-drop functionality of bringing in various elements of launchd plists, each one is documented so you can see exactly what it does. Highly recommended.