-
Notifications
You must be signed in to change notification settings - Fork 0
/
ejecutar.c
52 lines (42 loc) · 1.23 KB
/
ejecutar.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
#include "minishell.h"
#include "parser.h"
#include "ejecutar.h"
#include "libmemoria.h"
pid_t ejecutar_orden (const char *orden, int *pbackgr)
{
char **args;
pid_t pid;
int indice_entrada;
int indice_salida;
if ((args=parser_orden(orden,&indice_entrada,&indice_salida,pbackgr))== NULL)
{
return(-1);
}
/* si la orden tiene redirecciones o tuberias, puede incluir aqui, fuera del */
/* ambito de esta practica, el codigo para tratamiento de esas redirecciones.*/
pid = fork();/*Crea el proceso hijo*/
if (pid!=0){/*Esto es el padre, ya que el pid 0 corresponde al hijo*/
/*printf("soy el padre\n");*//*comprobación*/
}
else{/*Esto es el Hijo, ya que el pid de este es 0*/
execvp(args[0], args);
}
free_argumentos(args);
return pid;
}
void ejecutar_linea_ordenes(const char *orden)
{
pid_t pid;
int backgr;
/* si la orden es compuesta, puede incluir aqui, fuera del ambito*/
/* de esta practica, el codigo para tratamiento de tuberias. */
pid = ejecutar_orden(orden,&backgr);
if (backgr!=0) {
waitpid(pid,&backgr,WNOHANG);
printf("Se está ejecutando en segundo plano, puede continuar usando la minishell mientras.\n");
}
else{
wait(&backgr);
}
return;
}