-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathejercicio_3.c
61 lines (44 loc) · 1.06 KB
/
ejercicio_3.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
57
58
59
60
61
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <errno.h>
#define MAX 256
int main (int argc, char *argv[], char *env[]) {
while (1) {
int proceso;
if ((proceso = vfork()) == -1) {
printf("%d", errno);
}
int contador = 0;
if (proceso == 0) {
for (int k = 0; env[k]; k++) {
contador++;
}
char varAux[MAX];
char* cadena[20];
char* token;
char delim[4] = " \n\t";
int i = 0;
printf("<%s>: ", getenv("HOME"));
fgets(varAux, MAX, stdin);
token = strtok(varAux, delim);
while (token != NULL) {
if (i == 20) break;
cadena[i] = token;
token = strtok(NULL, delim);
i++;
}
if (token == NULL && i < 20) {
cadena[i] = NULL;
}
env[contador + 1] = NULL;
execve(cadena[0], cadena, env);
perror("No se pudo ejecutar el programa ");
}
wait(NULL);
}
return 0;
}