I am getting segmentation fault in the following program. Why? And how to resolve it?
#include <stdio.h>
main()
{
int pid;
printf("I'm the original process with PID %d and PPID %d.\n", getpid(),getppid());
pid=vfork();
if (pid!=0)
{
printf("I'm the parent process with PID %d and PPID %d.\n",getpid(),getppid());
printf("My child's PID is %d.\n", pid);
}
else
{
printf("I'm the child process with PID %d and PPID %d.\n",getpid(),getppid());
}
}
Output:
I'm the original process with PID 18563 and PPID 18500.
I'm the child process with PID 18564 and PPID 18563.
I'm the parent process with PID 18563 and PPID 18500.
My child's PID is 18564.
Segmentation fault