Created
December 31, 2021 09:21
-
-
Save kougazhang/1bb74ace323746dd1610049f2df39bb4 to your computer and use it in GitHub Desktop.
#copy-on-write
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <unistd.h> | |
int main(void) { | |
pid_t fpid; // fpid 表示 fork 函数返回值 | |
int count=0; | |
// 调用 fork, 创建出子进程 | |
fpid = fork(); | |
// 所以下面的代码有两个进程执行 | |
if (fpid < 0) { | |
printf("create subprocess failed\n"); | |
} else if (fpid == 0) { | |
printf("i am subprocess\n"); | |
count++; | |
} else { | |
printf("i am father process\n"); | |
count++; | |
} | |
printf("the result of count is %d\n", count); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment