4

When running launchctl unload some.plist, what is this command translated to specifically, in terms of UNIX commands, etc.

There is nothing in .plist files that specifies any "command line to run when the user specifies unload", so does macOS simply send a kill signal to the process? Or what does it do?

8

SIGTERM

launchd's unload command sends a SIGTERM signal to the associated job's child processes.

Detached Processes

If a process launched by a launchd job has detached from it's parent process, then unload will not affect that process. This is often the case for daemonised processes.

Original Source Code

You can download and inspect the original launchd source code. launchd has since been rewritten and is proprietary to Apple but the original documents the intended behaviour on unload.

  • Very good answer! So it's SIGTERM, then. My next question is whether there's a standard UNIX (or macOS) way to know when a stopping a daemon has been completely finalised, because the prompt doesn't wait for that, does it? I'll be happy to post a new question about that if it doesn't fit within the scope of this question. – forthrin Aug 5 '18 at 14:42
  • 1
    A modern UNIX process can use kqueue to be notified when a process terminates, see stackoverflow.com/questions/22960188 and Chrome's kill_mac.cc source. For more detailed answers and to ask for shell specific answers, please ask a new question. – Graham Miln Aug 5 '18 at 14:55
2

To best answer this question we can look at two things: UNIX commands and what is in a .plist.

Starting out with a .plist, the following code is usually there

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>CFBundleExecutable</key>
  <string>someApplication</string>
</dict>
</plist>

The CFBundleExecutable identifies the name of the bundle’s main executable file. For an app, this is the app executable. For a loadable bundle, it is the binary that will be loaded dynamically by the bundle.

So typing launchctl unload some.plist will tell MacOS the key to locate the bundle’s executable file and 'unload' it or essentially kill it from the system. This is telling it at an application level.

When using a UNIX command such as kill <PID> it is in reference to a specific process.

Looking at what is a Process vs Application here is good reading


You can read further into what is in .plists and how they work over at Apple

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .