I have a process [command line cpp application] which i want to run always such as it should relaunch after a crash, after device startup etc.
I created a launchd Property List File with KeepAlive true and placed under /Library/LaunchDaemons.
Problem Statements:
I have a bash script to start and stop this process.
start using: launchctl bootstrap
.
stop involve these two steps:
- send SIGTERM signal and wait untill process stops after doing some cleanups
- launchctl bootout [It doesn't sends SIGTERM]
during steps 1 - Process is getting stop, but also getting immediate relaunch by launchctl
during step 2 - it getting stop again.
is there a proper way so that we can disable KeepAlive temporarily so that process will not launch during step 1? or suggest other ways to handle this?
So, you want to get the SIGTERM
as part of the stopping process? If so, start a transaction in your daemon. That’ll mark it as ‘busy’, so the stop will send you a SIGTERM
before the inevitable SIGKILL
.
Annoyingly, there isn’t a better public API for starting a transaction than xpc_transaction_begin
(r. 37489913).
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"