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\'
It is printing the statement twice because it is printing it for both the parent and the child. The parent has a parent id of 0
Try something like this:
pid_t pid;
pid = fork();
if (pid == 0)
printf("This is the child process. My pid is %d and my parent's id is %d.\n", getpid(),getppid());
else
printf("This is the parent process. My pid is %d and my parent's id is %d.\n", getpid(), getppid() );