#include <stdio.h>
#include <stdlib.h>
int main()
{
int pid;
printf("1) before the fork
");
pid = fork();
printf("2) after the fork
");
if (pid == 0)
{
printf("3) i am the child process, my pid is %d
", getpid());
printf("my parent has the pid %d
", getppid());
exit(1);
}
else
{
printf("i am the parent process, my pid is %d
", getpid());
printf("my parent has the pid %d
", getppid());
exit(0); //the father of the father is the terminal
}
}
// THIS ONLY WORKS ON LINUX