Linux 下使用rtcwake实现定时休眠和唤醒设备

查看是否安装rtcwake

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

查看rtcwake帮助

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

 

执行该命令的时候需要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进行调整。


原文链接:https://blog.csdn.net/bulreed/article/details/19907691

上一篇:CSP2019 树上的数 题解


下一篇:前端内存查看的几种方式