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該怎麼一步步解釋?
謝謝