Are there suspend\resume signals in Linux?

扶醉桌前 提交于 2019-12-06 02:05:28

问题


My application needs to react on hibernation mode so it can do some action on suspending and other actions on resuming. I've found some distributive-specific ways to achieve it(Upower + DBus) but didn't find anything universal. Is there a way to do it?

Thanks!


回答1:


A simple solution to this is to use a self-pipe. Open up a pipe and periodically write timestamps to it. select on this pipe to read the timestamps and compare them to the current time. When there is a big gap, that means you have just woken up from system suspension or hibernate mode.

As for the other way around, there is not much time when the lid is closed and it flips the switch.

If you really need to act on suspend, then you will need to set powersave hooks like this https://help.ubuntu.com/community/PowerManagement/ReducedPower in pm-utils. It could be as simple as

kill -1 `cat mypid` ; sleep 1

Your process would then trap SIGHUP and do what needs to be done to prepare for suspension. The sleep delays the process long enough for your program to react to the signal.




回答2:


I believe you are looking for SIGSTOP and SIGCONT signals. You can send these to a running process like so:

kill -STOP pid
sleep 60
kill -CONT pid


来源:https://stackoverflow.com/questions/6136111/are-there-suspend-resume-signals-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!