Linux 休眠命令

休眠的类型

目前大概由三种类型的休眠:

suspend(suspend to RAM)

指的是除了内存以外的大部分机器部件都进入断电状态。 这种休眠状态恢复速度特别快,但由于内存中的数据并没有被保存下来,因此这个状态的系统并没有进入真正意义上的休眠状态,还在持续耗电。

hibernate(suspend to disk)

这种休眠会将内存中的系统状态写入交换空间内,当系统启动时就可以从交换空间内读回系统状态。 这种情况下系统可以完全断电,但由于要保存/读取系统状态到/从交换空间,因此速度会比较慢,而且需要进行一些配置(下面会说到)

hybrid(suspend to both)

结合了上面两种休眠类型。它像hibernate一样将系统状态存入交换空间内,同时也像suspend一样并不关闭电源。 这种,在电源未耗尽之前,它能很快的从休眠状态恢复。而若休眠期间电源耗尽,则它可以从交换空间中恢复系统状态。

suspend 休眠

进入 suspend 特别简单,无需额外的配置,在 systemd 系统上直接执行 systemctl suspend 就行了。

systemctl suspend

它的实际动作由 systemd-suspend.service 所定义, 在 archlinux 上,它长成这样子的:

#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
 
[Unit]
Description=Suspend
Documentation=man:systemd-suspend.service(8)
DefaultDependencies=no
Requires=sleep.target
After=sleep.target
 
[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/systemd-sleep suspend

参考链接:

https://cloud.tencent.com/developer/article/1170392
https://cloud.tencent.com/developer/information/linux%20%20%E4%BC%91%E7%9C%A0

    原文作者:莫讠
    原文地址: https://www.jianshu.com/p/ff91f6baae17
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞