阅读背景:

C fork调用中的奇怪输出

来源:互联网 

I have the following C code.

我有以下C代码。

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>


int main ()
{

    int i=1;

    pid_t child_pid = fork();

    if (child_pid == 0) 
    {
        printf ("%d\n", i++);
        printf ("%d\n", i++);
        printf ("This is child process.");
        return 0;


    }
    else if (child_pid > 0) {
        printf ("%d\n", i++);
        printf ("This is parent process.");
    }

    else {
    printf("Fork failed");
    }

}
#incl



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: