I am trying to create a program that uses fork() to create a new process. The sample output should look like so:
This is the child process. My pid is 733 and my parent\'
We control fork() process call by if, else statement. See my code below:
int main()
{
int forkresult, parent_ID;
forkresult=fork();
if(forkresult !=0 )
{
printf(" I am the parent my ID is = %d" , getpid());
printf(" and my child ID is = %d\n" , forkresult);
}
parent_ID = getpid();
if(forkresult ==0)
printf(" I am the child ID is = %d",getpid());
else
printf(" and my parent ID is = %d", parent_ID);
}