Hi everyone,
I'm trying to accomplish the following; I need to create 2 subprocesses and each subprocess should create a process of their own.
Should look like this:
I'm child xxxx parent xxxx
I'm the subchild xxxx parent xxxx
I'm the second child xxxx parent xxxx
I'm the second subchild xxxx parent xxxx
So far I have this
#include <stdio.h>
int main()
{
int pid;
pid = fork();
if (pid) {
printf("I'm the parent %d\n", getpid());
} else {
printf("I'm the child %d parent %d\n", getpid(), getppid());
pid = fork();
if (pid) {
} else {
printf("I'm the subchild %d parent %d\n", getpid(), getppid());
}
}
return 0;
}
The above creates a child process and another process but for some reason it does not get the PPID from the child it's been created from. I wonder why is this.
The current output looks like:
I'm the parent 6213
I'm the child 6214 parent 6213
I'm the subchild 6215 parent 1
The subchild's parent should be 6214. Some help would be greatly appreciated