1. 程式人生 > >Linux下利用rtcwake喚醒裝置

Linux下利用rtcwake喚醒裝置

轉自https://blog.csdn.net/bulreed/article/details/19907691

 

以下是在OpenSuse上所做的測試

whereis rtcwake
rtcwake: /usr/sbin/rtcwake /usr/share/man/man8/rtcwake.8.gz

rtcwake --help
Usage:
 rtcwake [options]

Options:
 -d, --device <device>    select rtc device (rtc0|rtc1|...)
 -n, --dry-run            does everything, but suspend
 -l, --local              RTC uses local timezone
 -m, --mode <mode>        standby|mem|... sleep mode
 -s, --seconds <seconds>  seconds to sleep
 -t, --time <time_t>      time to wake
 -u, --utc                RTC uses UTC
 -v, --verbose            verbose messages

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see rtcwake(8).

 standby

普通待機模式,為預設選項,對應ACPI  state S1

 mem

待機到記憶體,即記憶體之外把其他裝置都進入低功耗模式,對應ACPI state S3

 disk

待機到硬碟,即休眠,把電腦的當前狀態儲存到硬碟,幾乎不消耗外部電源,對應ACPI state S4

off 

通過呼叫系統的關機命令來休眠, 對應ACPI state S5

 

可以通過以下命令查閱當前系統支援的休眠模式

cat /sys/power/state
standby mem disk

 

我的電腦目前支援以上三種,但是測試發現休眠到disk的時候,機器會迅速醒來,standby和mem兩種模式則工作正常,箇中原因還不清楚。

 

執行該命令的時候需要root許可權

1. 系統休眠後20seconds喚醒,加-v選項可以看到更多的列印資訊

sudo rtcwake -v -s 20 -m mem 或

sudo rtcwake -v -s 20 -m standby

列印資訊:

rtcwake -v -s 20 -m mem
Using UTC time.
delta   = 0
tzone   = 0
tzname  = UTC
systime = 1393296617, (UTC) Tue Feb 25 02:50:17 2014
rtctime = 1393296617, (UTC) Tue Feb 25 02:50:17 2014
alarm 0, sys_time 1393296617, rtc_time 1393296617, seconds 20
rtcwake: wakeup from "mem" using /dev/rtc0 at Tue Feb 25 02:50:38 2014
suspend mode: mem; suspending system

 

2. 系統在指定的時間醒來

rtcwake -v -t `date -d 10:53 +%s` -m mem
Using UTC time.
delta   = 0
tzone   = 0
tzname  = UTC
systime = 1393296754, (UTC) Tue Feb 25 02:52:34 2014
rtctime = 1393296754, (UTC) Tue Feb 25 02:52:34 2014
alarm 1393296780, sys_time 1393296754, rtc_time 1393296754, seconds 0
rtcwake: wakeup from "mem" using /dev/rtc0 at Tue Feb 25 02:53:00 2014
suspend mode: mem; suspending system

 

rtcwake -v -t `date -d 10:54 +%s` -m standby
Using UTC time.
delta   = 0
tzone   = 0
tzname  = UTC
systime = 1393296794, (UTC) Tue Feb 25 02:53:14 2014
rtctime = 1393296794, (UTC) Tue Feb 25 02:53:14 2014
alarm 1393296840, sys_time 1393296794, rtc_time 1393296794, seconds 0
rtcwake: wakeup from "standby" using /dev/rtc0 at Tue Feb 25 02:54:00 2014
suspend mode: standby; suspending system

 

如果發現systime 和rtctime時間不一致,需要利用hwclock進行調整。