dwa*_*ter 135
将信号发送0
到给定的PID
只检查是否有任何给定的进程PID
正在运行并且您有权向其发送信号.
有关更多信息,请参阅以下联机帮助页:
杀(1)$ man 1 kill
...
If sig is 0, then no signal is sent, but error checking is still performed.
...
Run Code Online (Sandbox Code Playgroud)
杀(2)
$ man 2 kill
...
If sig is 0, then no signal is sent, but error checking is still performed; this
can be used to check for the existence of a process ID or process group ID.
...
Run Code Online (Sandbox Code Playgroud)
Tod*_*obs 124
...很难找到关于这个特殊信号的文档.尽管其他人已经说过,但man 1 kill
在基于Debian的系统中唯一提到的信号是:
特别有用的信号包括HUP,INT,KILL,STOP,CONT和0.
不是特别有用,特别是如果您还不知道信号的作用.它也没有列出输出kill -l
,所以除非你已经知道它,否则你不会知道它.
在Debian和Ubuntu系统上,输出部分man 2 kill
说:
如果sig为0,则不发送信号,但仍然执行错误检查; 这可用于检查是否存在进程ID或进程组ID.
您可以kill -0
用来检查进程是否正在运行.考虑这些例子.
# Kill the process if it exists and accepts signals from
# the current user.
sleep 60 &
pid=$!
kill -0 $pid && kill $pid
# Check if a PID exists. When missing, this should result
# in output similar to:
# bash: kill: (6228) - No such process
# Exit status: 1
kill -0 $pid; echo "Exit status: $?"
Run Code Online (Sandbox Code Playgroud)
您还可以使用它kill -0
来确定当前用户是否有权发出给定进程的信号.例如:
# See if you have permission to signal the process. If not,
# this should result in output similar to:
# bash: kill: (15764) - Operation not permitted
# Exit status: 1
sudo sleep 60 &
kill -0 $!; echo "Exit status: $?"
Run Code Online (Sandbox Code Playgroud)
此命令检查$ pid中的PID是否处于活动状态.
小智 5
Kill -0 $ pid用于检查带有pid的进程是否存在。
使用'kill -0 $ pid'检查进程存在时要小心,因为
一旦预期的进程退出,则可以将其pid分配给其他新创建的进程。(因此,不能肯定特定进程是否存在)
在僵尸进程的情况下,哪个孩子正在等待父级呼叫等待。在此,它持有$ pid并在该进程未运行时给出正结果。
归档时间: |
|
查看次数: |
54082 次 |
最近记录: |