Suppose that the process id of parent process and child process are 1999 and 2013 respectively. List the output generated at Line X, Y and Z.
父,子行程的process id 分别为1999 以及2013。请写出Line X, Y and Z 的输出。
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#define SIZE 5
int nums[SIZE] = {0, 1, 2, 3, 4};
int main()
{
int i;
pid_t pid;
pid = fork();
if (pid == 0) {
for (i = 0; i < SIZE; i++) {
nums[i] *= -i;
printf(" %d ", nums[i]); /* LINE X */
}
}else if (pid > 0) {
printf("My Process ID is %d \n", getpid()); /* LINE Y */
wait(NULL);
for (i = 0; i < SIZE; i++)
printf(" %d ", nums[i]); /* LINE Z */
}
return 0;
}
上面这个习题找不到讲义或有用的网页来了解原理
请问有人知道创造pid的forking该怎么一步步解释?
谢谢