gpt4 book ai didi

linux - 如何从初始 PID 命名空间以外的 PID 命名空间和初始 PID 命名空间调用 reboot()?

转载 作者:太空宇宙 更新时间:2023-11-04 10:04:04 30 4
gpt4 key购买 nike

manpage of reboot()

Behavior inside PID namespaces

Since Linux 3.4, if reboot() is called from a PID namespace other
than the initial PID namespace
with one of the cmd values listed
below, it performs a "reboot" of that namespace: the "init" process
of the PID namespace is immediately terminated, with the effects
described in pid_namespaces(7).

The values that can be supplied in cmd when calling reboot() in this case are as follows:

LINUX_REBOOT_CMD_RESTART, LINUX_REBOOT_CMD_RESTART2 The "init" process is terminated, and wait(2) in the parent process reports that the child was killed with a SIGHUP signal.

LINUX_REBOOT_CMD_POWER_OFF, LINUX_REBOOT_CMD_HALT The "init" process is terminated, and wait(2) in the parent process reports that the child was killed with a SIGINT signal.

For the other cmd values, reboot() returns -1 and errno is set to
EINVAL.

看完its manpage,我对PID命名空间的理解有限.我想知道如何调用 reboot()

  • 来自初始 PID 命名空间以外的 PID 命名空间,以及
  • 来自初始 PID namespace ?

最佳答案

您可以使用 nsenter 进入其他 PID 命名空间。从初始 PID 命名空间以外的 PID 命名空间执行重启:

/usr/bin/nsenter -p/proc/PID/ns/pid reboot

如果目标PID为1:

/usr/bin/nsenter -p/proc/1/ns/pid reboot

第二个问题与简单地调用 reboot 相同,因为它会获取当前的 PID 上下文。

关于linux - 如何从初始 PID 命名空间以外的 PID 命名空间和初始 PID 命名空间调用 reboot()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53858292/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com