如何使用C在Linux中检测系统是否将进入待机状态 [英] How to detect whether system is going to standby in Linux using C
问题描述
我想知道如何在Linux中使用C来检测系统是否将进入待机模式.为此,我在Windows中找到了一条名为 WM_POWERBROADCAST
的消息,该消息会在发送之前发送进入睡眠模式.
I want to know how I can detect whether the system is going to a standby mode in Linux using C. I found a message called WM_POWERBROADCAST
in windows for that purpose, which sends this message before going to the sleep mode.
对于Linux,C语言中还有其他替代方法吗?
Is there any alternatives in C, for Linux?
我听说DBus可以用于相同的目的,有人可以进一步解释吗?
I heard that DBus can be used for same purpose, could somebody explain it more?
推荐答案
最后我找到了解决方案.
Finally I found a solution.
我们可以使用pm实用程序.
We can use the pm utility for that.
如果将任何shell脚本放在/etc/pm/sleep.d文件夹中,它将在系统进入睡眠状态之前和系统恢复之后自动执行.
If you put any shell script in /etc/pm/sleep.d folder it will be executed automatically just before the system going to sleep and after the system is resumed.
内容将类似于
#!/bin/bash
case $1 in
suspend)
#suspending to RAM
/home/harikrishnan/Desktop/sleepd Sleeping
;;
resume)
#resume from suspend
sleep 3
/home/harikrishnan/Desktop/sleepd Woken
;;
esac
此处将使用参数执行/home/harikrishnan/Desktop/sleeped程序
here it will execute the /home/harikrishnan/Desktop/sleepd program with the arguments
这篇关于如何使用C在Linux中检测系统是否将进入待机状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!