#include #include #include using namespace std; int main(){ int loopCount = 5; // each process will get its own loopCount cout << "I am still only one process." << endl; pid_t returnedValue = fork(); if(returnedValue < 0){ // still only one process perror("error forking"); // report the error return -1; } else if (returnedValue == 0){ // this must be the child process while(loopCount > 0){ cout << "I am the child process." << endl; loopCount--; // decrement child's counter only sleep(1); // wait a second before repeating } } else { // this must be the parent process while(loopCount > 0){ cout << "I am the parent process; my child's ID is " << returnedValue << "." << endl; loopCount--; // decrement parent's counter only sleep(1); } } return 0; }