-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlancian.c
56 lines (52 loc) · 947 Bytes
/
lancian.c
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
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
if (argc < 3) {
printf("Expected 2 parameters");
return -1;
}
int n = atoi(argv[1]);
for (int i = 0; i < n; i++) {
int status;
if (fork() == 0) {
execvp(argv[2], argv + 2);
exit(status);
} else {
wait(&status);
}
}
return 0;
}
/*
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
int n = atoi(argv[1]);
int i;
char *copia;
for (i = 0; i < n; i++) {
switch (fork()) {
case 0:
asprintf(&copia, "%d", i);
setenv("NCOPIA", copia, 1);
free(copia);
execvp(argv[2], argv + 2);
exit(1);
case -1:
exit(1);
default:
break;
}
}
for (i = 0; i < n; i++) {
int status;
wait(&status);
}
}
*/