#include #include #include #include #include #include #include using namespace std; int main() { pid_t pid; // process id pid = fork(); // spawn child process if (pid < 0) { perror("fork"); exit(10); } if (pid == 0) { // child cout << "child process running" << endl; // do something here for (int i=0; i<100000000; ++i); cout << "child done" << endl; return 0; } // parent cout << "child process pid:" << pid << endl; waitpid(pid, 0, 0); // wait for child process to finish cout << "parent done" << endl; return 0; }