O/P is not coming properly....(fork() system call)
Hey, i want to create a child of a child process i have written some codes which is working but it's output is not coming properly...
Code:
#include<stdio.h>
#include<sys/types.h>
void main()
{
pid_t pid,pid1;
pid=fork();
if(pid == 0)
{
printf("\nThis is the child of main process with pid=%d and parent id= %d",getpid(),getppid());
pid=fork();
if(pid == 0)
{
printf("\nThis is child of child process with pid = %d and ppid= %d",getpid(),getppid());
}
}
printf("\nProcess with pid %d is terminating.",getpid());
}
AND OUTPUT IS:-
Process with pid 2185 is terminating.
This is the child of main process with pid=2186 and parent id= 2185
Process with pid 2186 is terminating.This is the child of main process with pid=2186 and parent id= 2185
This is child of child process with pid = 2187 and ppid= 1
Process with pid 2187 is terminating.
================================================== =========
In the output if process 2186 is terminated then how again it's printing the next line
which is getting duplicated and that's also without any newline??