#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
int main()
{
pid_t pid, pid1;
//fork a child process
pid = fork();
if (pid< 0) //error occurred
{
fprintf(stderr, "Fork Failed");
return 1;
}
elseif (pid == 0) //child process
{
pid1 = getpid();
printf("child: pid = %d", pid); //line A
printf("child: pid1 = %d", pid1); //line B
}
else //parent process
{
pid1 = getpid();
printf("parent: pid = %d", pid); //line C
printf("parent: pid1 = %d", pid1); //line D
wait(NULL);
}
return 0;
}
My question is what would the output be if the parent pid was 2600 and the child pid was 2603? Is there a way to use those variables in the program. JUst by looking, I would think it would produce 0, 2600, 2600, 2603. Is this right?