为什么我在bash中的kill -9命令上没有收到信号SIGKILL? [英] Why I am not getting signal SIGKILL on kill -9 command in bash?

查看:39
本文介绍了为什么我在bash中的kill -9命令上没有收到信号SIGKILL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在bash脚本中,我按以下方式处理不同的信号:

In bash script I handle different signal as follows:

#!/bin/bash

sighdl () 
{
  echo "signal caught"
  #do something
  exit 0
}

trap sighdl SIGKILL SIGINT SIGTERM

以上代码正确处理了以下活动:

Above code handle signal properly for following activity:

  1. Ctrl + C
  2. kill pid
  3. pkill脚本名称
  1. Ctrl+C
  2. kill pid
  3. pkill scriptname

对于 kill -9 pid ,它不会调用 sighdl .根据我的理解(如果我没记错的话), kill -9 发送SIGKILL信号.

For kill -9 pid it does not call sighdl. As per my understanding (if I am not wrong) kill -9 sends the SIGKILL signal.

有什么主意吗?

推荐答案

您不能这样做.是9是 SIGKILL ,由于安全原因,Unix系统设计上不允许任何脚本/程序捕获 SIGKILL .否则,任何脚本都会捕获&忽略SIGKILL,这将使OS无法终止该脚本.

You cannot do that. Yes 9 is SIGKILL and Unix system by design doesn't allow any script/program to trap SIGKILL due to security reasons. Otherwise any script can trap & ignore SIGKILL which will make impossible to terminate that script by OS.

这篇关于为什么我在bash中的kill -9命令上没有收到信号SIGKILL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆