1
0
UAHCode/CPE435/Lab2/lab2_ex4_orphan.cpp

23 lines
643 B
C++
Raw Normal View History

2022-08-28 21:12:16 +00:00
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 childs 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( ));
}
}