Guest User

Untitled

a guest
Dec 10th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <sys/types.h>
  5.  
  6. int main() {
  7.  
  8. pid_t proceso;
  9.  
  10. proceso = fork();
  11.  
  12.  
  13. if (proceso > 0) //[PADRE]
  14. {
  15. printf("[PADRE] PID: %d \n", getpid());
  16. // Como se hace para saber la lista de hijos y su respectivo PID ??
  17. wait(); //Si no esta este WAIT pasaria lo q pide el punto C), el padre terminaria sin importar el estado del hijo aunque éste seguiria ejecutandose como hijo del INIT y con el mismo standar output que le habia asignado el padre.
  18. }
  19. else
  20. if (proceso == 0) //[HIJO]
  21. {
  22. int i;
  23. printf("[HIJO] PID: %d \n PPID: %d \n", getpid(),getppid());
  24. for (i=1; i < 11; i++)
  25. {
  26. printf("Numero de iteracion: %d \n", i);
  27. sleep(1);
  28. }
  29. exit(EXIT_SUCCESS);
  30. }
  31. else // [ERROR]
  32. {
  33. printf("[ERROR] No se pudo crear el hijo \n");
  34. }
  35. printf("[MAIN] FIN %d \n", getpid());
  36. exit(EXIT_SUCCESS);
  37. }
Add Comment
Please, Sign In to add comment