简体   繁体   English

Linux中延迟的内核恐慌

[英]Delayed kernel panic in Linux

For our tests we need to trigger kernel panic on a remote server (VM), via SSH: 对于我们的测试,我们需要通过SSH在远程服务器(VM)上触发内核崩溃:

ssh server "echo c > /proc/sysrq-trigger"

The problem is that in most cases the SSH session gets stuck, since the kernel panic happens before the connection is disconnected. 问题在于,在大多数情况下,SSH会话会卡住,因为内核恐慌会在断开连接之前发生。 There is a generic connection timeout, but this is not good enough. 有一个通用的连接超时,但这还不够好。

Is there a way to delay the panic? 有没有办法延迟恐慌?

We tried to put the following in a file on the server: 我们尝试将以下内容放入服务器上的文件中:

# - panic.sh -

#/bin/bash
sleep 5
echo c > /proc/sysrq-trigger

And then to execute it: 然后执行它:

ssh server "nohup panic.sh &"

But this didn't help. 但这没有帮助。 The SSH session waits till the sleep ends. SSH会话一直等到睡眠结束。

This happens because your script keeps all pipes open, so ssh has to wait to see if you'll write more. 发生这种情况是因为您的脚本使所有管道保持打开状态,所以ssh必须等待看是否还要编写更多内容。

If you close them all, ssh knows it won't receive any more output and will exit: 如果您全部关闭它们, ssh知道它将不再收到任何输出,并且将退出:

$ time ssh localhost 'sleep 5 < /dev/null > log 2>&1 &'
real    0m0.171s
user    0m0.013s
sys     0m0.003s

You can also do this from within the script using the exec command before the sleep: 您还可以在睡眠之前使用exec命令从脚本内执行此操作:

exec < /dev/null > log 2>&1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM