加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 透明地冻结和解冻进程?

发布时间:2020-12-14 02:55:46 所属栏目:Linux 来源:网络整理
导读:我正在寻找一种方法来透明地冻结(暂停)一个过程,然后再解冻它.这可以通过SIGSTOP实现,但是SIGSTOP会通知父节点(通过从waitpid返回),例如,导致bash将交互式进程放入后台(该方法的问题将在 in this link中更详细地描述). cgroup子系统has a way to accomplish
我正在寻找一种方法来透明地冻结(暂停)一个过程,然后再解冻它.这可以通过SIGSTOP实现,但是SIGSTOP会通知父节点(通过从waitpid返回),例如,导致bash将交互式进程放入后台(该方法的问题将在 in this link中更详细地描述).

cgroup子系统has a way to accomplish this通过写入/ sys / fs / cgroup / freezer /中的文件,但只适用于cgroup级别 – 也就是说,一次只能冻结整组进程/线程.我想通过安排将每个进程放在它自己的cgroup中可以解决这个问题,但这似乎有点麻烦,而且可能因为systemd等而存在危险.已经将cgroup用于自己的目的.

我非常接近只编写一个内核模块,将底层的freeze_task API暴露给用户空间,但我真的希望尽可能避免这样做!

解决方法

我能够使用这些方向轻松地冻结和解冻单个过程(xeyes): https://www.kernel.org/doc/Documentation/cgroup-v1/freezer-subsystem.txt

我知道它与您链接的文档相同,但我没有看到这样做的问题.您可以轻松编写脚本/程序来自动执行此操作并根据需要冻结单个进程.

在我的Ubuntu 16.04系统上,/ sys / fs / cgroup / freezer已经存在,所以我跳过了那一部分.

* Examples of usage :

   # mkdir /sys/fs/cgroup/freezer    
   # mount -t cgroup -ofreezer freezer /sys/fs/cgroup/freezer    
   # mkdir /sys/fs/cgroup/freezer/0   
   # echo $some_pid > /sys/fs/cgroup/freezer/0/tasks

to get status of the freezer subsystem :

   # cat /sys/fs/cgroup/freezer/0/freezer.state    THAWED

to freeze all tasks in the container :

   # echo FROZEN > /sys/fs/cgroup/freezer/0/freezer.state    
   # cat /sys/fs/cgroup/freezer/0/freezer.state    FREEZING    
   # cat /sys/fs/cgroup/freezer/0/freezer.state    FROZEN

to unfreeze all tasks in the container :

   # echo THAWED > /sys/fs/cgroup/freezer/0/freezer.state    
   # cat /sys/fs/cgroup/freezer/0/freezer.state    THAWED

我不知道如何清理.我无法删除0目录.但我确信有办法.

这是否足够好还是还有其他需要的东西?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读