Process Scheduling: What are Cron, Anacron, Systemd and Launchd?

Operating systems enable the easy use of computers and other digital devices. macOS is used on the Apple Mac and iOS on the iPhone. In order for the whole thing to work, there are visible interfaces, interaction options and programs, but also processes, system services and scripts running in the background and therefore not visible. A part of these background tasks is the scheduler, which automatically starts, controls and ends certain system tasks and maintenance processes. One of the first Unix-based schedulers was called Cron. This is still suitable for servers today. On computers come more likely Anacron or Systemd to use – on macOS it is launchd.

The first scheduler in Unix-based operating systems was called cron and brought with it cronjobs and the crontab. Launchd is now used on the Apple Mac as a daemon for scheduling and many other tasks.
The first scheduler in Unix-based operating systems was called cron and brought with it cronjobs and the crontab. Launchd is now used on the Apple Mac as a daemon for scheduling and many other tasks.

Cron: The beginnings of scheduling on the computer

Cron (from the Greek "chronos" for "time") has long been the standard tool for scheduling in Unix-like operating systems. Originally developed in the 1970s, cron allowed computer users to define tasks to run at specific times, on specific days, or at predefined intervals. 

This ranged from system maintenance tasks to notifications and reporting (log generation). Cron served its purpose for a long time, but it also had its limitations. For example, a user had to be logged in for cron to run. Cron is still used on servers today, as it is very well suited for permanently running systems.

What is a cron job?

A cron job is a task that is scheduled and executed by the cron scheduler. It is therefore a time-based executed process, a program or a script. A cron job can be set by the system, by an app or by the user in order to schedule specific times for individual tasks or to repeatedly execute a command at a specific interval. System maintenance, backing up data, creating reports (log files) and cleaning up databases are examples of use here. 

What is a crontab?

To define and schedule cron jobs, there is a crontab (“tab” stands for table). In Unix-based operating systems, it is a configuration file that can be viewed as a kind of time overview or timetable. In the crontab overview, the execution times with different dates are set for individual commands, processes, scripts, apps and the like - month, day of the month, day of the week, hour, minute and / or other. The crontab table can be edited in the command line or in the Port view and edit. Various crontab commands are available for this.

The crontab table consists of six columns, the last of which is used for the command to be executed. The five columns in front of the command determine the time of execution for the same, so that when reading the table permanently, the time reached is recognized and the command can be executed at the end of the line. The five scheduling columns are usually divided as follows:

  • Minute (0-59): The minute within an hour when the task should run.
  • Hour (0-23): The hour of the day when the task should run.
  • Day of Month (1-31): The day of the month on which to run the task.
  • Month (1-12): The month in which to run the task.
  • Day of the week (0-6): The day of the week (Sunday to Saturday) on which to run the task; the value 7 can also be used to represent Sunday (thus dividing the week from 1-7).

More modern solutions such as Anacron, Systemd and Launchd are mostly backwards compatible with cronjobs and crontab, so these Unix technologies can still be used with the appropriate terminal commands for manual scheduling.

Anacron: Missed tasks are simply made up for

Anacron was developed as an advanced cron technology to address some weaknesses of cron - e.g. B. the dependency on an active user. In the case of many tasks that should be carried out at fixed times, there was also the risk that they would simply be missed if the corresponding user was not logged in. 

Anacron solved this problem by customizing tasks so that they could still be performed even if they were missed. For this purpose, past tasks were queried and checked whether they delivered a result or were noted in a log. If this was not the case, they were made up for. Anacron is therefore useful for computers and laptops that do not run continuously.

Systemd: initialization system, scheduling and more in one

The name systemd consists of "system" for the operating system and "d" as an abbreviation for daemon. A daemon is a background process (more on this here: What is a daemon?). But systemd is more than just a single background process, it includes a so-called init system. The abbreviation init stands for "initialization" and indicates that this is about starting the operating system and loading the processes, services and resources required for this. 

Or to put it briefly: Systemd is a collection of processes that ensures the operation of a system and offers various schedules and regularities for it. At the top of the list is the systemd-init process, which is called first (process ID 1) and controls the start, monitoring and termination of other processes, mostly daemons running in the background. Other systemd components provide crontab capabilities, create log files, and more.

The shortest summary is provided by Wikipedia entry on the subject: "systemd is the daemon that starts and maintains the system."

Launchd: init system since Mac OS X 10.4 Tiger

Until finally Mac OS X 10.3 Panthers From 2003, Apple relied on the standard init process for the Mac to start the system and cron to schedule the system. Since Mac OS X 10.4 Tiger, which accompanied the transition from PowerPC Macs to models with Intel processors from 2005 to 2007, Launchd is used as a collection of initialization processes and scheduling. The launchd daemon is comparable to systemd and also provides a framework for managing other daemons and tasks. Launchd consists of "Launch" for starting the system and "d" for daemon(s).

Similar to systemd in other Unix-based systems, launchd is also responsible for the system start, i.e. the boot process, on computers with macOS. Thus, Launchd is also assigned the process ID 1. In addition, this parent daemon, along with the daemons it starts and other background tasks, runs while the operating system is active and in use. Switching on the computer and using the operating system can be imagined in a very simplified way as a four-step process, which is divided up as follows:

  • The firmware is loaded to verify the hardware and enable it for use.
  • The kernel and its extensions are loaded, and then the kernel activates launchd.
  • Launchd starts and searches the system and user daemon directories, resulting in the loading of the individual settings. The login window is then shown.
  • While the Mac is switched on (and if macOS is actively used), Launchd runs certain background processes and cron jobs according to the system and user plist files and the crontab.

Launchd on Mac: Faster launches and more efficient systems

But Launchd also handles other complex tasks. It was designed by Apple for resource-saving efficiency. In practical terms, this means, among other things, that only the necessary daemons are loaded when the system is started and when the user logs in. Other daemons are only loaded when they are really needed. 

For example, the "OnDemand" key can be assigned for network daemons so that Launchd only loads them when they are needed for a network request ("on demand"). The result is that the operating systems tend to run faster or smoother with Launchd. This may allow compatibility with older, slower hardware.

The role of plist files in using Launchd

As noted above, on the Apple Mac, Launchd loads specific settings, configurations, and daemons for task management. Among other things, they are loaded from system directories (e.g. /System/Library/LaunchDaemons), which specify certain properties and tasks of the respective operating system. But also from user directories (e.g. /Library/LaunchDaemons), which contain the individual settings, configurations, extensions and login items of the users.

They are each stored in a property list, or plist for short. The plist files in these and other directories under macOS are used, among other things, to customize the system and run background processes. In addition to directly visible effects, they are also used to index content (e.g. B. for Spotlight) or for Bluetooth settings. If they have errors, problems can arise. This is why some Mac troubleshooting guides advise deleting certain plist files.

Further information can be found in Jens' posts:

Summary of the topic

Actually I just wanted to write a post about cron, cronjobs and crontab. But these Unix scheduling technologies are no longer used in their original form on the Apple Mac. That's why I showed the development of the scheduling daemons based on it. From Anacron via Systemd, the path then led to Launchd, which has been used under Mac OS X, OS X and macOS for some time now. I hope I was able to explain the functionality of Launchd and how it relates to the system, individual user accounts and plist files in an understandable way.

Here are some sources for further and, above all, more technically extensive reading:

  • Wikipedia article on cron daemon: Here
  • Wikipedia article on Anacron: Here
  • Wikipedia article on systemd: Here
  • Wikipedia article on Launchd: Here

My tips & tricks about technology & Apple

Did you like the article and did the instructions on the blog help you? Then I would be happy if you the blog via a Steady Membership would support.

9 Responses to “Process Scheduling: What are Cron, Anacron, Systemd and Launchd?”

  1. I bought a MacBook Pro M2 Pro 2023. My old Mac still had an Intel processor, 7 years old. The difference, the new one doesn't get warm. Whether I will buy a new one again in 7 years is an open question. These parts are not cheap. But anyone who has had to work with Windows computers will appreciate an Apple. Hardware and software from one source. Because of the memory is not sooo nice. You have to take what is on offer.
    I'll take a closer look at your portal.
    Oh yes, do you have a description of how Apple stores the data, except on documents.
    If I don't set up a folder for it. For example: the templates for Pages or Numbers.

    1. Hello Falk! Yes, Macs are always a bit more expensive, but personally I think the price is fair if it saves me the headaches I've had with my PC.
      Regarding your question: I didn't understand it correctly. What exactly do you mean by "how Apple stores the data"?

  2. I totally agree about the price and stuff.
    Because of the data, Pages and Numbers have templates that I can choose from and I can secure my particular template. The function of the library is not so clear to me. Some things have been added under Sonoma. These are areas that run in the background. Tha'ts what I meant.

    1. Hi Falk! Sorry if I'm so obtuse. I don't quite get it… you're talking about Pages for example. Where is there a library? Do you mean the “books” under the templates? Or am I totally screwed? 😂

    1. Hello Falk.

      First: don't be cheeky!

      Second, how about you ask your question properly, so people know what you want in the first place?

      After all, under a post that has absolutely nothing to do with your question topic, you write a comment about your Mac purchase and your experiences that are unrelated to anything. Then you refer to another post without naming it exactly (how about posting your question under that very post so you can categorize it thematically?). Furthermore, it is sometimes about templates, sometimes about the library and then about the fact that something has been added in Sonoma. How is one supposed to understand exactly what you want?

      So, instead of insinuating that someone is clueless here, you should explain properly what your problem is and what your exact question is. I tried my best to understand what you want. But that's just not possible.

    2. Hi Falk! Even if you already had feedback from Johannes. I'm really amazed how quickly your mood changes just because someone who wants to help you asks twice. Perhaps it would be more constructive for you to consider whether your comments might also be wrong or misunderstood and one or two questions are justified.
      I'm opting out now because I don't engage in discussions with trolls who use the anonymity of the internet to behave like the ax in the woods. Have fun on other websites! Regards Jens

  3. You know, a connoisseur knows what I'm talking about. It's best we don't go on.
    There are enough contacts who can answer my questions without any problems because they know what is at stake. OK?? I think you didn't read my text properly.

Post a comment

Your e-mail address will not be published. Required fields are marked with * marked

In the Sir Apfelot Blog you will find advice, instructions and reviews on Apple products such as the iPhone, iPad, Apple Watch, AirPods, iMac, Mac Pro, Mac Mini and Mac Studio.

Specials
Shopping
  •  
  •