https://access.redhat.com/solutions/1266703
What signal 0 does in kill command?
SOLUTION 已验证 - 已更新 2014年十一月13日03:47 -
环境
- Red Hat Enterprise Linux 6.4
- util-linux
问题
- What signal 0 does in kill command?
- when I execute "kill -0 PID" and PID is the id of a thread, the command exit without errors.
[root@host ~]# ps -eo pid,comm|grep -c 10252
0
[root@host ~]# kill -0 10252;echo $?
0
[root@host ~]# cat /proc/18020/task/10252/stat
10252 (imsd) S 1 18020 18020 0 -1 4202560 4 0 0 0 2 1 0 0 19 -1 1351 0 987845280 615174144 118443 18446744073709551615 134512640 139793320 4286914320 3934351508 4151395376 0 16391 4096 16391 18446744071580550505 0 0 -1 8 0 0 3 0 0
- Is that the correct behavior of kill -0 command ?
决议
- From the man page of kill,
If sig is 0, then no signal is sent, but error checking is still performed.
- This means, it just checks errors, doesn't kill the process.
[root@example~]# ps aux | grep rsyslog
root 1117 0.0 0.2 1077544 42684 ? Ssl 06:02 0:02 /sbin/rsyslogd -n
root 8196 0.0 0.0 112680 2248 pts/0 S+ 13:24 0:00 grep --color=auto rsyslog
[root@example~]# kill -0 1117
[root@example~]# echo $?
0
[root@example~]# ps aux | grep rsyslog
root 1117 0.0 0.2 1077544 42684 ? Ssl 06:02 0:02 /sbin/rsyslogd -n
root 8198 0.0 0.0 112680 2184 pts/0 S+ 13:24 0:00 grep --color=auto rsyslog
- We can see, if we specify the signal 0, it will just check for the errors and will not kill the process. This is a expected behaviour.