used wait function to prevent parentless child
This commit is contained in:
parent
c0e25b38d4
commit
b7d6eb4352
2
p2.c
2
p2.c
|
@ -2,6 +2,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
pid_t id_actual, id_padre, pid;
|
pid_t id_actual, id_padre, pid;
|
||||||
|
@ -18,6 +19,7 @@ void main(void) {
|
||||||
printf ("Soy el proceso hijo\n\t");
|
printf ("Soy el proceso hijo\n\t");
|
||||||
printf(" Mi PID es %d, y el mi papa %d\n",getpid(),getppid());
|
printf(" Mi PID es %d, y el mi papa %d\n",getpid(),getppid());
|
||||||
} else { // Nos encontramos en el padre
|
} else { // Nos encontramos en el padre
|
||||||
|
id_actual = wait(NULL);
|
||||||
printf("Yo soy el padre de la criatura:\n\t");
|
printf("Yo soy el padre de la criatura:\n\t");
|
||||||
printf("Mi PID es %d, el de mi padre (abuelo de la criatura) es %d.\n\t",
|
printf("Mi PID es %d, el de mi padre (abuelo de la criatura) es %d.\n\t",
|
||||||
getpid(),getppid());
|
getpid(),getppid());
|
||||||
|
|
Loading…
Reference in New Issue