Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <stdlib.h>
- int
- main(int argc, char** argv) {
- int n = strtol(argv[1], NULL, 10);
- int counter = 0;
- pid_t pid;
- do {
- ++counter;
- printf("%d", counter);
- if (counter != n) {
- putchar(' ');
- }
- else {
- putchar('\n');
- }
- fflush(stdout);
- pid = fork();
- } while (pid == 0 && counter < n);
- if (pid > 0) {
- int status;
- waitpid(pid, &status, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement