However, when launchctl unload happens, the /usr/bin/open process disappears but the process spawned by open remains.
Right. This is because, if a job is started when you unload it,
launchd
terminates it before the unload. This termination process uses UNIX signals, and it targets the process group assigned to the job. If you fork/exec from a launchd job, the child process ends up in the same process group as the parent (see
killpg
), and thus the child process gets terminated. OTOH, the
open
tool runs the app via NSWorkspace, which causes it to act just like it was launched by the user from Finder, which means it’s in a different process group, and thus doesn’t get terminated.
Note Some of this is discussed in
launchd.plist
.
It’s generally not a good idea to run a GUI app directly as a launchd agent. You would typically have the agent start the app and then have some other mechanism to terminate it. The best way to do that depends on your specific circumstances. Can you explain more about the big picture here?
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"