What Is Launchctl?- Components & Usage 2020

In 2005, Apple Inc. released its launchd. Parts of it are launchd and launchctl. What are these? What is launchctl?

Defining Launchd

This is an ‘init and operating system service management daemon’. Moreover, launchd is part of macOS. One of its purposes is to replace BSD-style init and System Starter.

Launchd comprises two major components. These are the launchd and launchctl. 

Launchd

This is responsible for managing the daemons. This works at both the system and user level. Moreover, launchd works the same as xinetd. Because this can also start daemons on demand.

In addition, launchd is also similar to watchdogd. Because launchd is also responsible for monitoring daemons. The purpose of monitoring is to ensure that the daemons are kept on the run.

Moreover, launchd changed init into PID 1 on macOS. Because of this, it can enable the starting system at boot time.

Service parameters are defined by configuration files. These are also run by launchd. These are stored in two subdirectories. Namely, LaunchAgents and LaunchDaemons. These are all inside the library folders. These files can be set into 30 different keys. 

However, launchd itself cannot work alone with these configuration files. Launchd does not have the ability to read these files. Thus, this needs help from its component partner. And that is the launchctl.

Launchd’s Main Tasks

  • First, launchd is responsible for booting the system.
  • Second, launchd is for loading and maintaining services.

What Is Launchctl?

This serves as the partner component of the launchd. This works as a command-line application. It can read the said configuration files.

  • Launchctl does this by communicating with launchd. This is done with the help of IPC. 
  • Moreover, it can parse property list files. These property list files are connected in describing launchd jobs. 
  • Also, this is responsible for serializing the files. Serializing is done with the help of a specialized dictionary protocol. In addition, this one is something that launchd also understands.
  • This loads and unloads daemons.
  • Also, launchctl can start and stop launchd controlled jobs.
  • It can get system utilization statistics, and its child processes.
  • Set environment settings.
  • Centralizes the control of services.

Thus, these two (launchd and launchctl) both work together. Each plays a role in the system. Yes, dependencies exist between the two.

More Launchctl Capabilities

Launchctl can do more. The following are some of its capabilities.

  • It can take commands from the command line. This ranges from operating in interactive mode and standard in. 
  • Make global changes using launchctl. However, this is only possible when you have superuser privileges.
  • To make launchctl commands permanent, store these in /etc/launchd.conf.
  • Moreover, launchctl connects with launchd with the help of a Mac-specific IPC mechanism.

Property List- Definition

This is also known as plist. This file is useful for program configuration, specifically in launchd. 

For example, launchd first scans a folder. Or suppose launchctl submits a job. This further analyzes and reads the plist file. This file then describes the way programs are to be run.

Some of the keys used are the following:

  • Label
  • Program
  • ProgramArguments
  •  UserName
  • OnDemand
  • RunAtLoad
  • WatchPaths

Rate this post:

Leave a Comment

Your email address will not be published.