23 lines
643 B
C++
23 lines
643 B
C++
using namespace std;
|
||
#include <iostream>
|
||
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <sys/types.h>
|
||
#include <unistd.h>
|
||
int main(int argc, char * argv[])
|
||
{
|
||
int pid;
|
||
pid = fork();
|
||
if (pid == 0) {
|
||
printf("I am the child, my process id is %d\n",getpid( ));
|
||
printf("the child’s parent process id is %d\n",getppid( ));
|
||
sleep(20);
|
||
printf("I am the child, my process id is %d\n",getpid( ));
|
||
printf("I am the child, parent's process id is %d\n",getppid( ));
|
||
} else
|
||
{
|
||
printf("I am the parent, my process id is %d\n",getpid( ));
|
||
printf("the parents parent process id is %d\n",getppid( ));
|
||
}
|
||
}
|