launchctl remove vs unload

Questions and Answers about all things *OS (macOS, iOS, tvOS, watchOS)

launchctl remove vs unload

Postby philstokes » Wed Oct 04, 2017 3:24 pm

I'm trying to figure out the difference between calling
Code: Select all
launchctl remove
Code: Select all
 launchctl unload
on a job, aside from the fact that one is called on a label and the other a path.

I know both are considered legacy commands, but is there any practical difference in what happens under the hood?

Posts: 2
Joined: Tue Sep 19, 2017 6:55 am

Re: launchctl remove vs unload

Postby stek29 » Sat Oct 07, 2017 11:54 pm

unload calls `load_and_unload_cmd` and remove calls `start_stop_remove_cmd`.

Quick look through source shows that:
- `load_and_unload_cmd` calls `unloadjob` on each job and also changes overrides file. `unloadjob` seems to send `VPROC_MAGIC_UNLOAD_SIGNAL` signal, which causes launchd to call `job_remove`.
- `start_stop_remove_cmd` just sends message to launchd with dict like {"path": "RemoveJob"}. That dict is likely processed in `ipc.c` and `job_remove` is called.

So `launchctl unload` has more options, can modify override list, and uses some private hacky stuff to make launchd remove that job, while `lauchctl remove` just tells launchd to remove the `job`.
Posts: 1
Joined: Sat Oct 07, 2017 12:55 pm

Re: launchctl remove vs unload

Postby morpheus » Mon Oct 09, 2017 6:01 pm

More correctly, unload works on a plist, and remove works on by label.. The implementation is vastly different - the open source link is just old and outdated (it no longer reflects launchctl or launchd).
Site Admin
Posts: 532
Joined: Thu Apr 11, 2013 6:24 pm

Return to Questions and Answers

Who is online

Users browsing this forum: No registered users and 1 guest