gpt4 book ai didi

linux - `trap` -ing Linux 信号 - SIGSTOP?

转载 作者:行者123 更新时间:2023-12-05 00:55:58 24 4
gpt4 key购买 nike

Docker docs请注意以下有关如何运行 clean up 的(带代码)在容器关闭时:

Lastly, if you need to do some extra cleanup ... on shutdown, ..., you may need to ensure that the ENTRYPOINT script receives the Unix signals, passes them on, and then does some more work


#!/bin/sh

trap "echo TRAPed signal" HUP INT QUIT KILL TERM

/usr/sbin/apachectl start

我认为这个 trap会抓到 KILL信号。但是,我在此阅读 post :

All signals except for SIGKILL and SIGSTOP can be intercepted by the process.



然而,另一个 post状态:

There is one signal that you cannot trap: SIGKILL or signal 9.



是哪个?

最佳答案

你无法捕捉到 SIGSTOP。您引用的页面有误。

是的,上面的脚本试图捕捉 KILL 信号。它失败。您可以使用以下脚本轻松验证这一点:

#!/bin/sh

echo "Running shell in pid $$"
trap "echo TRAPed signal" HUP INT QUIT KILL TERM STOP

sleep 20

尝试向它发送 KILL 和 STOP 信号,您将看到进程分别终止和停止,而没有打印消息。如果您尝试任何其他捕获的信号,您将看到它们按预期处理。

关于linux - `trap` -ing Linux 信号 - SIGSTOP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37164161/

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