<s>
launchd	B-Application
is	O
an	O
init	B-Operating_System
and	O
operating	B-Operating_System
system	I-Operating_System
service	I-Operating_System
management	I-Operating_System
daemon	B-Operating_System
created	O
by	O
Apple	O
Inc	O
.	O
as	O
part	O
of	O
macOS	B-Application
to	O
replace	O
its	O
BSD-style	O
init	B-Operating_System
and	O
SystemStarter	B-Operating_System
.	O
</s>
<s>
There	O
have	O
been	O
efforts	O
to	O
port	O
launchd	B-Application
to	O
FreeBSD	B-Operating_System
and	O
derived	O
systems	O
.	O
</s>
<s>
There	O
are	O
two	O
main	O
programs	O
in	O
the	O
launchd	B-Application
system	O
:	O
launchd	B-Application
and	O
launchctl	O
.	O
</s>
<s>
launchd	B-Application
manages	O
the	O
daemons	B-Operating_System
at	O
both	O
a	O
system	O
and	O
user	O
level	O
.	O
</s>
<s>
Similar	O
to	O
xinetd	B-Operating_System
,	O
launchd	B-Application
can	O
start	O
daemons	B-Operating_System
on	O
demand	O
.	O
</s>
<s>
Similar	O
to	O
watchdogd	B-Application
,	O
launchd	B-Application
can	O
monitor	O
daemons	B-Operating_System
to	O
make	O
sure	O
that	O
they	O
keep	O
running	O
.	O
</s>
<s>
launchd	B-Application
also	O
has	O
replaced	O
init	B-Operating_System
as	O
PID	B-Device
1	I-Device
on	O
macOS	B-Application
and	O
as	O
a	O
result	O
it	O
is	O
responsible	O
for	O
starting	O
the	O
system	O
at	O
boot	B-Operating_System
time	I-Operating_System
.	O
</s>
<s>
Configuration	O
files	O
define	O
the	O
parameters	O
of	O
services	O
run	O
by	O
launchd	B-Application
.	O
</s>
<s>
launchd	B-Application
itself	O
has	O
no	O
knowledge	O
of	O
these	O
configuration	O
files	O
or	O
any	O
ability	O
to	O
read	O
them	O
-	O
that	O
is	O
the	O
responsibility	O
of	O
"	O
launchctl	O
"	O
.	O
</s>
<s>
launchctl	O
is	O
a	O
command	O
line	O
application	O
which	O
talks	O
to	O
launchd	B-Application
using	O
IPC	B-Operating_System
and	O
knows	O
how	O
to	O
parse	O
the	O
property	B-Application
list	I-Application
files	O
used	O
to	O
describe	O
launchd	B-Application
jobs	O
,	O
serializing	O
them	O
using	O
a	O
specialized	O
dictionary	O
protocol	O
that	O
launchd	B-Application
understands	O
.	O
</s>
<s>
launchctl	O
can	O
be	O
used	O
to	O
load	O
and	O
unload	O
daemons	B-Operating_System
,	O
start	O
and	O
stop	O
launchd	B-Application
controlled	O
jobs	O
,	O
get	O
system	O
utilization	O
statistics	O
for	O
launchd	B-Application
and	O
its	O
child	O
processes	O
,	O
and	O
set	O
environment	O
settings	O
.	O
</s>
<s>
launchd	B-Application
has	O
two	O
main	O
tasks	O
.	O
</s>
<s>
The	O
first	O
is	O
to	O
boot	B-Operating_System
the	O
system	O
,	O
and	O
the	O
second	O
is	O
to	O
load	O
and	O
maintain	O
services	O
.	O
</s>
<s>
Here	O
is	O
a	O
simplified	O
view	O
of	O
the	O
Mac	B-Application
OS	I-Application
X	I-Application
Tiger	I-Application
system	B-Operating_System
startup	I-Operating_System
on	O
a	O
PowerPC	B-Architecture
Mac	O
(	O
on	O
an	O
Intel	O
Mac	O
,	O
EFI	B-Architecture
replaces	O
Open	B-Architecture
Firmware	I-Architecture
and	O
boot.efi	B-Operating_System
replaces	O
BootX	B-Operating_System
)	O
:	O
</s>
<s>
Open	B-Architecture
Firmware	I-Architecture
activates	O
,	O
initializes	O
the	O
hardware	O
,	O
and	O
then	O
loads	O
BootX	B-Operating_System
.	O
</s>
<s>
BootX	B-Operating_System
loads	O
the	O
kernel	O
,	O
spins	O
the	O
pinwheel	O
cursor	O
,	O
and	O
loads	O
any	O
needed	O
kernel	B-Application
extensions	I-Application
(	O
kexts	B-Application
)	O
.	O
</s>
<s>
The	O
kernel	O
loads	O
launchd	B-Application
.	O
</s>
<s>
launchd	B-Application
runs	O
/etc/rc	B-Device
,	O
various	O
scripts	O
which	O
scan	O
through	O
/System/Library/LaunchDaemons	O
and	O
/Library/LaunchDaemons	O
,	O
calling	O
launchctl	O
on	O
the	O
plists	B-Application
as	O
needed	O
,	O
then	O
launchd	B-Application
starts	O
the	O
login	O
window	O
.	O
</s>
<s>
These	O
directories	O
are	O
all	O
kept	O
in	O
the	O
typical	O
Library	O
directories	O
of	O
Mac	B-Operating_System
OS	I-Operating_System
X	I-Operating_System
.	O
</s>
<s>
launchd	B-Application
is	O
very	O
different	O
from	O
SystemStarter	B-Operating_System
in	O
that	O
it	O
may	O
not	O
actually	O
launch	O
all	O
the	O
daemons	B-Operating_System
at	O
boot	B-Operating_System
time	I-Operating_System
.	O
</s>
<s>
Key	O
to	O
launchd	B-Application
,	O
and	O
similar	O
to	O
xinetd	B-Operating_System
,	O
is	O
the	O
idea	O
of	O
launch-on-demand	O
daemons	B-Operating_System
.	O
</s>
<s>
When	O
launchctl	O
scans	O
through	O
the	O
job	O
plists	B-Application
at	O
boot	B-Operating_System
time	I-Operating_System
,	O
it	O
asks	O
launchd	B-Application
to	O
reserve	O
and	O
listen	O
on	O
all	O
of	O
the	O
ports	O
requested	O
by	O
those	O
jobs	O
.	O
</s>
<s>
If	O
so	O
indicated	O
in	O
the	O
plist	B-Application
by	O
the	O
"	O
OnDemand	O
"	O
key	O
,	O
the	O
daemon	B-Operating_System
is	O
not	O
actually	O
loaded	O
at	O
the	O
time	O
.	O
</s>
<s>
Rather	O
,	O
launchd	B-Application
will	O
listen	O
on	O
the	O
port	O
,	O
start	O
the	O
daemon	B-Operating_System
when	O
needed	O
,	O
and	O
shut	O
it	O
down	O
when	O
it	O
is	O
no	O
longer	O
needed	O
.	O
</s>
<s>
After	O
a	O
daemon	B-Operating_System
is	O
loaded	O
,	O
launchd	B-Application
will	O
keep	O
track	O
of	O
it	O
and	O
make	O
sure	O
it	O
is	O
running	O
if	O
needed	O
.	O
</s>
<s>
In	O
this	O
way	O
it	O
is	O
like	O
watchdogd	B-Application
,	O
and	O
shares	O
watchdogd	B-Application
's	O
requirement	O
that	O
processes	O
do	O
not	O
attempt	O
to	O
fork	O
or	O
daemonize	O
on	O
their	O
own	O
.	O
</s>
<s>
If	O
a	O
process	O
goes	O
into	O
the	O
background	O
,	O
launchd	B-Application
will	O
lose	O
track	O
of	O
it	O
and	O
attempt	O
to	O
relaunch	O
it	O
.	O
</s>
<s>
Mac	B-Application
OS	I-Application
X	I-Application
Tiger	I-Application
,	O
consequently	O
,	O
boots	O
much	O
faster	O
than	O
previous	O
releases	O
.	O
</s>
<s>
The	O
system	O
only	O
has	O
to	O
register	O
the	O
daemons	B-Operating_System
that	O
are	O
to	O
run	O
and	O
does	O
not	O
actually	O
launch	O
them	O
until	O
they	O
are	O
needed	O
.	O
</s>
<s>
In	O
fact	O
,	O
the	O
progress	O
bar	O
that	O
appears	O
during	O
boot	B-Operating_System
time	I-Operating_System
is	O
just	O
a	O
placebo	O
application	O
(	O
named	O
WaitingForLoginWindow	O
)	O
that	O
does	O
not	O
really	O
show	O
anything	O
other	O
than	O
the	O
passage	O
of	O
time	O
.	O
</s>
<s>
The	O
hardest	O
part	O
to	O
manage	O
during	O
a	O
launchd	B-Application
boot	B-Operating_System
is	O
dependencies	O
.	O
</s>
<s>
SystemStarter	B-Operating_System
had	O
a	O
very	O
simple	O
system	O
of	O
dependencies	O
that	O
used	O
the	O
"	O
Uses	O
"	O
,	O
"	O
Requires	O
"	O
,	O
and	O
"	O
Provides	O
"	O
keys	O
in	O
the	O
plist	B-Application
of	O
a	O
startup	O
item	O
.	O
</s>
<s>
There	O
are	O
two	O
main	O
strategies	O
when	O
creating	O
launchd	B-Application
dependencies	O
on	O
Tiger	O
:	O
IPC	B-Operating_System
allows	O
daemons	B-Operating_System
to	O
talk	O
amongst	O
themselves	O
to	O
work	O
out	O
dependencies	O
,	O
or	O
daemons	B-Operating_System
can	O
watch	O
files	O
or	O
paths	O
for	O
changes	O
.	O
</s>
<s>
Using	O
IPC	B-Operating_System
is	O
much	O
more	O
subtle	O
than	O
the	O
SystemStarter	B-Operating_System
's	O
keys	O
and	O
requires	O
more	O
work	O
from	O
the	O
developer	O
,	O
but	O
it	O
may	O
lead	O
to	O
cleaner	O
and	O
quicker	O
startups	O
.	O
</s>
<s>
SystemStarter	B-Operating_System
was	O
still	O
supported	O
up	O
to	O
OS	B-Operating_System
X	I-Operating_System
Mountain	I-Operating_System
Lion	I-Operating_System
,	O
but	O
was	O
removed	O
in	O
OS	B-Device
X	I-Device
Yosemite	I-Device
.	O
</s>
<s>
In	O
launchd	B-Application
,	O
control	O
of	O
services	O
is	O
centralized	O
in	O
the	O
launchctl	O
application	O
.	O
</s>
<s>
With	O
superuser	B-Application
privileges	O
,	O
launchctl	O
can	O
be	O
used	O
to	O
make	O
changes	O
on	O
a	O
global	O
scale	O
.	O
</s>
<s>
A	O
set	O
of	O
launchctl	O
commands	O
can	O
be	O
made	O
permanent	O
when	O
stored	O
in	O
/etc/launchd.conf	O
.	O
</s>
<s>
(	O
A	O
per-user	O
~	O
/.launchd.conf	O
file	O
appears	O
to	O
have	O
been	O
considered	O
,	O
but	O
is	O
not	O
supported	O
in	O
any	O
existing	O
version	O
of	O
macOS	B-Application
.	O
)	O
</s>
<s>
launchctl	O
communicates	O
with	O
launchd	B-Application
via	O
a	O
Mach-specific	O
IPC	B-Operating_System
mechanism	O
.	O
</s>
<s>
A	O
property	B-Application
list	I-Application
(	O
plist	B-Application
)	O
is	O
a	O
type	O
of	O
file	O
that	O
launchd	B-Application
uses	O
for	O
program	O
configuration	O
.	O
</s>
<s>
When	O
launchd	B-Application
scans	O
a	O
folder	O
,	O
or	O
a	O
job	O
is	O
submitted	O
with	O
launchctl	O
,	O
it	O
reads	O
a	O
plist	B-Application
file	O
that	O
describes	O
how	O
the	O
program	O
is	O
to	O
be	O
run	O
.	O
</s>
<s>
For	O
a	O
full	O
list	O
,	O
see	O
Apple	O
's	O
manual	O
page	O
for	O
launchd.plist	O
.	O
</s>
<s>
By	O
convention	O
,	O
the	O
job	O
label	O
is	O
the	O
same	O
as	O
the	O
plist	B-Application
file	O
name	O
,	O
without	O
the	O
.plist	B-Application
extension	O
.	O
</s>
<s>
UserName	O
String(defaults to root or current user )	O
The	O
job	O
will	O
be	O
run	O
as	O
the	O
given	O
user	O
,	O
who	O
may	O
(	O
or	O
may	O
not	O
)	O
be	O
the	O
user	O
who	O
submitted	O
it	O
to	O
launchd	B-Application
.	O
</s>
<s>
RunAtLoad	O
Boolean(defaults to NO )	O
A	O
boolean	O
flag	O
that	O
defines	O
if	O
a	O
task	O
is	O
launched	O
immediately	O
when	O
the	O
job	O
is	O
loaded	O
into	O
launchd	B-Application
.	O
</s>
<s>
The	O
syntax	B-Application
is	O
similar	O
to	O
cron	B-General_Concept
.	O
</s>
<s>
RootDirectory	O
String	O
The	O
job	O
will	O
be	O
chrooted	B-Application
into	O
this	O
directory	O
before	O
execution	O
.	O
</s>
<s>
AbandonProcessGroup	O
Boolean(defaults to NO )	O
A	O
boolean	O
flag	O
that	O
defines	O
whether	O
subprocesses	O
launched	O
from	O
a	O
task	O
launched	O
by	O
launchd	B-Application
will	O
be	O
killed	O
when	O
the	O
task	O
ends	O
.	O
</s>
<s>
This	O
differs	O
from	O
systemd	B-Application
's	O
socket	O
activation	O
in	O
that	O
the	O
name	O
of	O
a	O
socket	O
definition	O
inside	O
of	O
the	O
job	O
configuration	O
is	O
hardcoded	O
into	O
the	O
application	O
.	O
</s>
<s>
This	O
protocol	O
is	O
less	O
flexible	O
,	O
although	O
it	O
does	O
not	O
,	O
as	O
systemd	B-Application
does	O
,	O
require	O
the	O
daemon	B-Operating_System
to	O
hardcode	O
a	O
starting	O
file	O
descriptor	O
(	O
as	O
of	O
2014	O
,	O
it	O
is	O
3	O
)	O
.	O
</s>
<s>
–	O
and	O
most	O
of	O
those	O
things	O
were	O
superseded	O
when	O
launchd	B-Application
was	O
introduced	O
with	O
Mac	B-Application
OS	I-Application
X	I-Application
v10.4	I-Application
(	O
Tiger	O
)	O
.	O
</s>
<s>
In	O
2005	O
,	O
R	O
.	O
Tyler	O
Croy	O
ported	O
launchd	B-Application
to	O
FreeBSD	B-Operating_System
as	O
part	O
of	O
Google	O
Summer	O
of	O
Code	O
Project	O
.	O
</s>
<s>
It	O
could	O
not	O
be	O
run	O
as	O
PID	B-Device
1	I-Device
(	O
only	O
a	O
session	O
init	B-Operating_System
)	O
,	O
and	O
it	O
was	O
not	O
commonly	O
used	O
on	O
that	O
platform	O
.	O
</s>
<s>
In	O
2006	O
,	O
the	O
Ubuntu	B-Operating_System
Linux	I-Operating_System
distribution	I-Operating_System
considered	O
using	O
launchd	B-Application
.	O
</s>
<s>
The	O
option	O
was	O
rejected	O
because	O
the	O
source	O
code	O
was	O
subject	O
to	O
the	O
Apple	B-License
Public	I-License
Source	I-License
License	I-License
–	O
described	O
as	O
an	O
"	O
inescapable	O
licence	O
problem	O
"	O
.	O
</s>
<s>
Ubuntu	B-Operating_System
instead	O
developed	O
and	O
switched	O
to	O
its	O
own	O
service	O
management	O
tool	O
,	O
Upstart	B-Device
.	O
</s>
<s>
In	O
August	O
2006	O
,	O
Apple	O
relicensed	O
launchd	B-Application
under	O
the	O
Apache	B-Application
License	I-Application
,	I-Application
Version	I-Application
2.0	I-Application
in	O
an	O
effort	O
to	O
make	O
adoption	O
by	O
other	O
open	O
source	O
developers	O
easier	O
.	O
</s>
<s>
Most	O
Linux	B-Application
distributions	I-Application
use	O
systemd	B-Application
or	O
Upstart	B-Device
,	O
or	O
continue	O
with	O
init	B-Operating_System
,	O
and	O
the	O
BSDs	B-Operating_System
also	O
continue	O
with	O
init	B-Operating_System
.	O
</s>
<s>
In	O
December	O
2013	O
,	O
R	O
.	O
Tyler	O
Croy	O
announced	O
his	O
intent	O
to	O
resume	O
work	O
on	O
his	O
port	O
of	O
launchd	B-Application
to	O
FreeBSD	B-Operating_System
,	O
and	O
his	O
"	O
openlaunchd	O
"	O
GitHub	O
repo	O
subsequently	O
rose	O
in	O
activity	O
.	O
</s>
<s>
The	O
last	O
Wayback	O
Machine	O
capture	O
of	O
the	O
Mac	B-Application
OS	I-Application
Forge	O
area	O
for	O
launchd	B-Application
was	O
in	O
June	O
2012	O
,	O
and	O
the	O
most	O
recent	O
open	O
source	O
version	O
from	O
Apple	O
was	O
in	O
code	O
for	O
OS	B-Operating_System
X	I-Operating_System
10.9.5	O
.	O
</s>
<s>
In	O
2014	O
,	O
with	O
OS	B-Device
X	I-Device
10.10	I-Device
and	O
iOS	B-Application
8	O
,	O
Apple	O
moved	O
code	O
for	O
launchd	B-Application
to	O
closed	B-Application
source	I-Application
libxpc	O
.	O
</s>
<s>
In	O
August	O
2015	O
Jordan	O
Hubbard	O
and	O
Kip	O
Macy	O
announced	O
NextBSD	B-Operating_System
,	O
which	O
is	O
based	O
on	O
FreeBSD-CURRENT	O
kernel	O
while	O
adding	O
in	O
Mach	B-Operating_System
IPC	B-Operating_System
,	O
Libdispatch	O
,	O
notifyd	O
,	O
asld	O
,	O
launchd	B-Application
,	O
and	O
other	O
components	O
derived	O
from	O
Darwin	O
,	O
Apple	O
's	O
open-source	O
code	O
for	O
OS	B-Operating_System
X	I-Operating_System
.	O
</s>
