如何在bash中使用kill SIGUSR2? [英] how to use kill SIGUSR2 in bash?
问题描述
我使用iptraf监视linux中的网络流量,而shell命令是(使iptraf在后台运行):
I use iptraf to monitor the network traffic in linux, and the shell command is(make iptraf running in background):
iptraf -s eth0 -f -B -L ./traffic.dat
如果要得到结果,我必须先停止iptraf,所以我使用shell命令:
if I want to get the result, I have to stop iptraf first, so I use the shell command:
kill -SIGUSR2 $pid
但是,如果我将这些shell命令移到bash脚本文件(net.sh)中,我将无法停止iptraf,但会收到错误消息:
however, I could not stop iptraf if I move these shell commands into a bash script file(net.sh), and I get an error:
kill: SIGUSR2: invalid signal specification
我在脚本文件(net.sh)中使用了"kill -l",但是我发现没有名称为SIGUSR2的参数.如果我使用USR2或-9,我将一无所获.
I use 'kill -l' in the script file(net.sh), and I find there is no parameter which name is SIGUSR2. and I would get nothing if I use USR2 or -9.
完整的脚本文件是:
iptraf -s eth0 -f -B -L ./temp.txt
pid=`ps -ef | grep iptraf | grep -v grep | awk '{print $2}'`
kill -USR2 $pid
cat temp.txt
这些命令后我什么也没得到.
I get nothing after these commands.
如果我想得到结果该怎么办?
what shoud I do if I want to get the result?
推荐答案
SIGUSR2
是依赖于体系结构的,并且其值可以超出31
,12
或17
. man 7 signal
中对此进行了描述.您必须找出哪个值适合您的系统.通常,这可以通过查看以下内容来完成:
SIGUSR2
is architecture depended and can have a value out of 31
, 12
or 17
. This is described in man 7 signal
. You'll have to find out which value is appropriate for your system. Usually this is done by having a look into:
/usr/include/asm/signal.h
在我的系统上-Ubuntu 12.04 AMD 64-其值为12
:
On my system - Ubuntu 12.04 AMD 64 - it has a value of 12
:
#define SIGUSR2 12
一旦您知道系统上SIGUSR2
的正确数值,就可以使用以下方式发送该信号:
Once you know the proper numeric value for SIGUSR2
on your system, you can send this signal using:
kill -SIGNO PID
# In this case
kill -12 PID
这篇关于如何在bash中使用kill SIGUSR2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!