fkill.c

来自「基于网络编程的例子」· C语言 代码 · 共 39 行

C
39
字号
/* * fkill.c - Send a signal using kill(2) */#include <sys/types.h>#include <wait.h>#include <unistd.h>#include <signal.h>#include <stdio.h>#include <stdlib.h>int main(void){     pid_t child;     int errret;      if((child = fork()) < 0) {	  perror("fork");	  exit(EXIT_FAILURE);     } else if(child == 0) {	/* in the child process */	  sleep(30);     } else {			/* in the parent */	  /* send a signal that gets ignored */	  printf("sending SIGCHLD to %d\n", child);	  errret = kill(child, SIGCHLD);	  if(errret < 0)	       perror("kill:SIGCHLD");	  else	       printf("%d still alive\n", child);	  /* now murder the child */	  printf("killing %d\n", child);	  if((kill(child, SIGTERM)) < 0)	       perror("kill:SIGTERM");	  /* have to wait to reap the status */	  waitpid(child, NULL, 0 );     }     exit(EXIT_SUCCESS);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?