#include #include // Headers for wait #include #include using namespace std; int main( int argc, char * argv[] ) { cout << "Original Process: PID=" << getpid() << " PPID=" << getppid() << endl; int pid = fork(); if( pid != 0 ) { // This is the parent process cout << "Parent Process: PID=" << getpid() << " PPID=" << getppid() << endl; int status; pid = wait( &status ); cout << "Parent Process: Child process " << pid << " terminated with status: " << (status >> 8) << endl; } else { // This is the child process cout << "Child Process: PID=" << getpid() << " PPID=" << getppid() << endl; cout << "Child Process calling exec" << endl; if( execl( "./prog.exe", "./prog", (char*)NULL ) == -1 ) { cout << "Error executing" << endl; } } cout << "Terminating Process PID=" << getpid() << endl; return 1; }