您的位置:首页 > 大数据 > 人工智能

kill and raise Functions

2016-03-05 16:37 507 查看

kill - send signal to a process

#include <sys/types.h>
#include <signal.h>

int kill(pid_t pid, int sig);
//return: 0 if OK, −1 on error


raise - send a signal to the caller

#include <signal.h>

int raise(int sig);
//return: 0 if OK, −1 on error


raise(signo)
等价于
kill(getpid(), signo)


4 conditions pid in kill

different conditions解释
pid > 0The signal is sent to the process whose process ID is pid.
pid == 0The signal is sent to all processes whose process group ID equals the process group ID of the sender and for which the sender has permission to send the signal. Note that the term all processes excludes an implementation-defined set of system processes. For most UNIX systems, this set of system processes includes the kernel processes and init (pid 1).
pid < 0The signal is sent to all processes whose process group ID equals the absolute value of pid and for which the sender has permission to send the signal. Again, the set of all processes excludes certain system processes, as described earlier.
pid == −1The signal is sent to all processes on the system for which the sender has permission to send the signal. As before, the set of processes excludes certain system processes.

signo参数

signo为0时,kill会执行一般的错误检查,但不发送信号。

用途: 用来检查特定的进程是否仍然存在。

如果不存在,
kill
返回-1,
errno
被设置为
ESRCH


进程的存在不是
atomic
原子性的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: