1
0
UAHCode/CPE435/Lab1/demo_1.cpp

20 lines
436 B
C++
Raw Permalink Normal View History

2022-08-28 21:12:16 +00:00
using namespace std;
#include <iostream>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char * argv[])
{
pid_t c_pid;
cout << "The pid of the parent is " << getpid() << endl;
c_pid = fork();
if (c_pid == 0 ) /* we are the child */
{
cout << "I am the child, my parents pid was " << getppid() << endl;
exit(0);
}
cout << "I am the parent, the child's pid is " << c_pid << endl;
exit(0);
}