Hi,
I need some help with using the fork() command. What I need to do is have the program create 3 child processes using fork() then each of the 3 child processes create 1 process each using fork(). Then I need the proces ID's of each process to be printed.
I have gotten the first part where I create 3 child processes, now I don't know where to insert another fork() such that each of the 3 child processes creates 1 child process of its own.
I am using the bash shell and using the "Pico" text editor to write this C Program. I am using the 'gcc' compile command to compile the program.
Here is the code I have so far:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
void main()
{
*int i;
*int n;
*pid_t childpid;
*for(i = 1; i < 4; ++i)
*{
* * if((childpid = fork()) <= 0)
* * {
* * * *break;
* * }
*}
*fprintf(stderr, "This process %ld with parent %ld\n", (long)getpid(), (long)getppid());
}