⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fkill.c

📁 基于网络编程的例子
💻 C
字号:
/* * 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -