What is launchd on macOS

220 阅读1分钟

launchd is a system-wide and per-user daemon/agent manager on MacOS.

Description

launchd manages processes, both for the system as a whole and for individual users.

The primary and preferred interface to launchd is via the launchctl(1) tool which (among other options) allows the user or administrator to load and unload jobs. Where possible, it is preferable for jobs to launch on demand based on criteria specified in their respective configuration files.

launchd also manages XPC services that are bundled within applications and frameworks on the system.

During boot launchd is invoked by the kernel to run as the first process (PID is 1) on the system and to further bootstrap the rest of the system.

image

You cannot invoke launchd directly.

Notes

On Darwin operating systems, the canonical way to launch a daemon is through launchd.

In the launchd lexicon, a daemon is, by definition, a system-wide service of which there is one instance for all clients. An agent is a service that runs on a per-user basis. Daemons should not attempt to display UI or interact directly with a user's login session. Any and all work that involves interacting with a user should be done through agents.

Running a service as a launchd agent or a per-user XPC service is the only way to run a process with a complete identity of that user.

In Nutshell, daemon, agent, XPC service are all service

FILES

  • ~/Library/LaunchAgents: Per-user agents provided by the user.
  • /Library/LaunchAgents: Per-user agents provided by the administrator.
  • /System/Library/LaunchAgents: Per-user agents provided by Apple.
  • /Library/LaunchDaemons: System-wide daemons provided by the administrator.
  • /System/Library/LaunchDaemons: System-wide daemons provided by Apple.

SEE ALSO

launchctl(1), launchd.plist(5)

DEVELOPER DOCUMENTATION

developer.apple.com/library/con…