-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseless_2.c
More file actions
46 lines (37 loc) · 1017 Bytes
/
useless_2.c
File metadata and controls
46 lines (37 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a, const void *b) {
return *(int*)a - *(int*)b;
}
int main(int argc, char *argv[]) {
int time_wait[256], i = 0;
char name_program[5][10];
FILE *file;
if(argc != 2) {
printf("Ошибка. Некорректно введены данные\n");
return 1;
}
if ((file = fopen(argv[1], "r")) == NULL) {
printf("Не удалось открыть файл\n");
return 2;
}
while ((fscanf(file, "%d %s", &time_wait[i], name_program[i])) && (!feof(file))) {
i = i + 1;
}
fclose(file);
//qsort(time_wait, i, sizeof(int), cmp);
for (int j = 0; j < i; j++) {
pid_t pid = fork();
if(pid < 0) {
printf("Не удалось создать процесс\n");
return 3;
}
if(pid == 0) {
sleep(time_wait[j]);
printf("\n");
execlp(name_program[j], name_program[j], NULL);
}
}
return 0;
}