/* createProc1.c++ creates a child process, prints pid and ppid */ #include using namespace std; #include #include #include #include #include int main() { // createProc1.c++ int chPID, status ; chPID = fork(); if(chPID == -1){ cerr << "fork() failed\n"; exit(1); } if(chPID > 0) { // parent // sleep(1); cout << "In parent: parent pid = " << getpid() << "\n" << "\tIn parent: child pid = " << chPID << "\n" ; waitpid(chPID, &status, 0) ; cout << "Child has finished" << endl; } else { // child sleep(1); cout << "In child: child pid = " << getpid() << "\n" << "\tIn child: parent pid = " << getppid() << "\n" ; } return 0 ; }