#include #include #include #include #include #include #include using namespace std; int x; void work(char c) { x = c; for (int i=0; i < 20; ++i) { for (int j=0; j < 10000000; ++j); cout << c << flush; } cout << " " << c << " " << x << " DONE " << endl; } int main() { pid_t pid; // process id pid = fork(); // spawn child process if (pid < 0) return pid; // error if (pid == 0) { // child work('A'); return 0; } // parent process work('B'); waitpid(pid, 0, 0); // wait for child return 0; }