Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- int main(int argc, char const* argv[]) {
- // strtol(char* num,.., base) - переводит число из массива чаров в long, при этом работая в сс с основанием base
- long N = strtol(argv[1], NULL, 10);
- int currentNumber = (int)N + 1;
- if (N == 1){
- printf("1\n");
- return 0;
- }
- pid_t process_id = 0;
- do {
- process_id = fork();
- if (process_id != -1) {
- currentNumber--;
- }
- }while (process_id == 0 && currentNumber != 1);
- if (process_id > 0) {
- int return_stat;
- waitpid(process_id, &return_stat, 0);
- if (currentNumber == N)
- printf("%d\n", currentNumber);
- else
- printf("%d ", currentNumber);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement