Kill命令模拟1
#include<sys/types.h> #include<signal.h> #include<stdio.h> #include<stdlib.h> #include<unistd.h> int main(int argc,char* argv[]) { pid_t pid_id=0; char* pid; if(argc!=2) { fprintf(stderr,"Usage: kill pid \n"); exit(1); } pid=argv[1]; while((*pid)!='\0') { pid_id=pid_id*10+(*pid-48); pid++; } if(kill(pid_id,SIGINT)) { fprintf(stderr,"Could not kill pid %d \n",pid_id); exit(1); } else { printf("Kill the pid %d successfully!\n",pid_id); } exit(0); }
功能只有结束给定PID的进程
用法: kill pid