一、 实例
编写一个函数,功能是杀死另一个进程;
#include<stdio.h> //printf()
#include<stdlib.h> //exit()
#include<unistd.h> //fork()
#include<signal.h>
int main(int argc, char const *argv[])
{
if(argc != 2)
{
printf("Please input pid\n");
return 0;
}
int pid =1;
sscanf(argv[1], "%d", &pid);
if(pid > 0)
{
kill(pid, SIGINT);
}
return 0;
}
通过ps -ef | grep p9查看到p9进程的id是2875。
重新打开一个终端,在命令行输入./p12 2875
p12是该可执行文件的名字;按下回车后······

p9进程被终止!
