1
0
UAHCode/CPE435/Lab2/lab2_ex4_orphan.cpp
2022-08-28 16:12:16 -05:00

23 lines
643 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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( ));
}
}