在Linux中,休眠主要分三个主要的步骤:
冻结用户态进程和内核态任务
调用注册的设备的suspend的回调函数
顺序是按照注册顺序
休眠核心设备和使CPU进入休眠态冻结进程是内核把进程列表中所有的进程的状态都设置为停止,并且保存下所有进程的上下文. 当这些进程被解冻的时候,他们是不知道自己被冻结过的,只是简单的继续执行.如何让Linux进入休眠呢?用户可以通过读写sys文件/sys /power/state 是实现控制系统进入休眠. 比如
# echo standby > /sys/power/state命令系统进入休眠. 也可以使用
# cat /sys/power/state来得到内核支持哪几种休眠方式.
AlarmManager.RTC_WAKEUP的方式
❑ RTC_WAKEUP
在指定的时刻(设置Alarm的时候),唤醒设备来触发Intent。
❑ RTC
在一个显式的时间触发Intent,但不唤醒设备。
❑ ELAPSED_REALTIME
从设备启动后,如果流逝的时间达到总时间,那么触发Intent,但不唤醒设备。流逝的时间包括设备睡眠的任何时间。注意一点的是,时间流逝的计算点是自从它最后一次启动算起。
❑ ELAPSED_REALTIME_WAKEUP
从设备启动后,达到流逝的总时间后,如果需要将唤醒设备并触发Intent。
Alarm的创建过程演示如下片段所示:
int alarmType = AlarmManager.ELAPSED_REALTIME_WAKEUP;
long timeOrLengthofWait = 10000;
String ALARM_ACTION = “ALARM_ACTION”;
Intent intentToFire = new Intent(ALARM_ACTION);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intentToFire, 0);
alarms.set(alarmType, timeOrLengthofWait, pendingIntent);
public void setRepeating(int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)
冻结用户态进程和内核态任务
调用注册的设备的suspend的回调函数
顺序是按照注册顺序
休眠核心设备和使CPU进入休眠态冻结进程是内核把进程列表中所有的进程的状态都设置为停止,并且保存下所有进程的上下文. 当这些进程被解冻的时候,他们是不知道自己被冻结过的,只是简单的继续执行.如何让Linux进入休眠呢?用户可以通过读写sys文件/sys /power/state 是实现控制系统进入休眠. 比如
# echo standby > /sys/power/state命令系统进入休眠. 也可以使用
# cat /sys/power/state来得到内核支持哪几种休眠方式.
AlarmManager.RTC_WAKEUP的方式
❑ RTC_WAKEUP
在指定的时刻(设置Alarm的时候),唤醒设备来触发Intent。
❑ RTC
在一个显式的时间触发Intent,但不唤醒设备。
❑ ELAPSED_REALTIME
从设备启动后,如果流逝的时间达到总时间,那么触发Intent,但不唤醒设备。流逝的时间包括设备睡眠的任何时间。注意一点的是,时间流逝的计算点是自从它最后一次启动算起。
❑ ELAPSED_REALTIME_WAKEUP
从设备启动后,达到流逝的总时间后,如果需要将唤醒设备并触发Intent。
Alarm的创建过程演示如下片段所示:
int alarmType = AlarmManager.ELAPSED_REALTIME_WAKEUP;
long timeOrLengthofWait = 10000;
String ALARM_ACTION = “ALARM_ACTION”;
Intent intentToFire = new Intent(ALARM_ACTION);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intentToFire, 0);
alarms.set(alarmType, timeOrLengthofWait, pendingIntent);
public void setRepeating(int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)