On Mar 24, 2011, at 10:27 AM, Jerry Krinock wrote: I want my non-GUI command-line program which is launched by user-level launchd to know as early as possible when shutdown is occuring, preferably (for example, if initiated by the console user) immediately when the user clicks the "Shut Down" button in the confirmation dialog, and, at least, before SIGTERMs start getting sent to processes. NSWorkspaceWillPowerOffNotification doesn't work, and IORegisterForSystemPower() doesn't work. Alternatively, I'd like an API to which I could ask before beginning a long task, "Is shutdown in progress?"
You should not do this, because what you are actually asking is "will shutdown be initiated during my long task", which is not something that can be answered.
Instead, you should ask yourself "how can I safely and quickly abort my long task in the rare circumstance where shutdown is signalled while it is in progress?".
= Mike
-- Ars longa, vita brevis, occasio praeceps, experimentum periculosum, iudicium difficile -- Hippocrates
|