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

📄 test9_4.txt

📁 linux under the C programming which complementary with the book of <linux under the C programming
💻 TXT
字号:
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>

void h_exit(int status);

int main(void)
{
    	pid_t pid;
    	int status;

    	if((pid=fork())<0)
    	{
        	printf("fork error!\n");
        	exit(0);
    	}
    	else if(pid==0)
        	exit(7);
    	if(wait(&status)!=pid)
    	{
        	printf("wait error!\n");
        	exit(0);
    	}
    	h_exit(status);

    	if((pid=fork())<0)
    	{
        	printf("fork error!\n");
        	exit(0);
    	}
    	else if(pid==0)
        	exit(1);
    	if(wait(&status)!=pid)
    	{
        	printf("wait error!\n");
        	exit(0);
    	}
    	h_exit(status);

    	if((pid=fork())<0)
    	{
        	printf("fork error!\n");
        	exit(0);
    	}
    	else if(pid==0)
        
    	if(wait(&status)!=pid)
    	{
        	printf("wait error!\n");
        	exit(0);
    	}
    	h_exit(status);

    	exit(0);
}


void h_exit(int status)
{
    	if(WIFEXITED(status))
        	printf("normal termination, exit status=%d .\n", WEXITSTATUS(status));
    	else if(WIFSIGNALED(status))
        	printf("abnormal termination, exit status=%d. \n", WTERMSIG(status));
}

⌨️ 快捷键说明

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