Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <cstdlib>
- using namespace std;
- int main () {
- pid_t pid;
- int i, n;
- cin >> n;
- for (i=1 ; i <= n; i++) {
- pid = fork();
- if (pid) break;
- cout << i;
- if (i == n) cout << endl;
- else cout << ' ';
- cout.flush();
- }
- wait(NULL);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement