I have a bash script (on osx) running continuously, it currently traps and handles a terminate like so
trap onshutdown TERM
how can I make trap also handle suspend/resume like
trap onsuspend ?
trap onresume ?
You're looking for signals SIGTSTP and SIGCONT. Try this:
|show 1 more comment|
Since the program is simply suspended and not reliably told, I would instead set up a named pipe and spawn a sentinel script.
It would simply loop every 5 or 15 minutes writing the current time stamp to the named pipe and then sleep.
You could then read from that pipe and do the math between reads - if the time jumps more than one or two pings, then you have slept.
Depending on how accurate you need the times, you could then tail the /private/var/log/system.log file (and potentially /private/var/log/system.0.log.gz) for the last sleep / wake times logged by the kernel.
It's going to be more work than relying on signals. You could also have the helper run itself and send whatever signal you want to your script.
Six of one, half dozen of the other.