找回密码
 立即注册
查看: 116|回复: 0

娈电浠诲ㄦ璇搴

[复制链接]

1872

主题

0

回帖

1872

积分

金牌会员

积分
1872
发表于 2023-8-26 21:58:14 | 显示全部楼层 |阅读模式
//鍐欎竴娈电畝鍗曠殑浠诲姟闂ㄦ祴璇曠▼搴
  1. // 鍐欎竴娈电畝鍗曠殑浠诲姟闂ㄦ祴璇曠▼搴#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <sys/types.h>#include <sys/types.h>#include <sys/wait.h>#include <errno.h>int main(int argc, char *argv[]){    int i;    int status;    int n = 5;    pid_t pid;    for (i = 0; i < n; i++)    {        pid = fork();        if (pid == 0)        {            break;        }        else if (pid < 0)        {            perror("fork");            exit(1);        }        else        {            continue;        }    }    if (i == n)    {        while (wait(&status) > 0)        {            if (WIFEXITED(status))            {                printf("child %d exit with code %d\n", WEXITSTATUS(status));                continue;            }            else if (WIFSIGNALED(status))            {                printf("child %d exit with signal %d\n", WTERMSIG(status));                continue;            }            else if (WIFSTOPPED(status))            {                printf("child %d exit with signal %d\n", WSTOPSIG(status));                continue;            }            else            {                printf("unknow status\n");                continue;            }        }        if (errno != ECHILD)        {            perror("wait");            exit(1);        }        else        {            printf("all child exit\n");            return 0;        }    }    else    {        sleep(i);        printf("child %d exit\n", i);        return 0;    }    return 0;}
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|翻墙党

GMT+8, 2026-10-2 18:49 , Processed in 0.061957 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表