Consider the following C program under Redhat 9.0:
1 #include < stdio.h >
2 #include < unistd.h >
3 #include < sys/wait.h >
4 #define N ???
5 int main(void)
6 {
7 int i;
8 int ProcessID;
9 int A;
10 A=0;
11 for (i=0;i < N;i++)
12 {
13 printf("Loop %d: Process ID=%d\n", i, getpid());
14 A=A+7;
15 while ((ProcessID=fork())== -1);
16 if (ProcessID==0)
17 {
18 printf("Process ID=%d, A=%d\n", getpid(), A);
19 }
20 else
21 {
22 wait(NULL);
23 }
24 }
25 }
The fork() function in line 15 makes a copy of the current process, returns pid of the son to the father process, and returns zero to the son process. After invoking fork(), the son process prints out a message in line 18 and continues with the next loop, while the father process waits for the end of the son in line 22. Remember that once been forked, the father process and the son process are independent, i.e having different local variables, and executed IN PARALLEL (but in the programs, since the father process always waits for its son's termination just after invoking fork(), actually there is often only one running process).
You are going to print the i-th line of the program's output. Assume the pid of the original process is 1000, and pids for new generated processes are increased by 1.