Page 1 of 1

launchctl remove vs unload

PostPosted: Wed Oct 04, 2017 3:24 pm
by philstokes
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?


Re: launchctl remove vs unload

PostPosted: Sat Oct 07, 2017 11:54 pm
by stek29
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`.

Re: launchctl remove vs unload

PostPosted: Mon Oct 09, 2017 6:01 pm
by morpheus
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).