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

📄 p7.17.c

📁 linux程序设计例程
💻 C
字号:
#include <stdio.h>#include <sys/wait.h>#include <stdlib.h>#include <unistd.h>int main(void){	pid_t pid,wait_pid;	int status;             	pid = fork();       	if (pid==-1)	{	       	perror("Cannot create new process"); 		exit(1); 	} else 	if (pid==0) {                     printf("child process id: %ld\n", (long) getpid());                   	       pause();               _exit(0);           } else {                    		   do {			   wait_pid=waitpid(pid, &status, WUNTRACED | WCONTINUED);						   if (wait_pid == -1) { 				   perror("cannot using waitpid function"); 				   exit(1); 			   }                   			   if (WIFEXITED(status))				   printf("child process exites, status=%d\n", WEXITSTATUS(status));			   			   if(WIFSIGNALED(status))				   printf("child process is killed by signal %d\n", WTERMSIG(status));			   			   if (WIFSTOPPED(status))				   printf("child process is stopped by signal %d\n", WSTOPSIG(status));			   			   if (WIFCONTINUED(status))				   printf("child process resume running....\n");               		   } while (!WIFEXITED(status) && !WIFSIGNALED(status));               		   exit(0);	   }}

⌨️ 快捷键说明

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