Guest User

Untitled

a guest
Jul 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <time.h>
  4.  
  5. int main(void)
  6. {
  7. int i;
  8. int quem;
  9. int filho1;
  10. int filho2;
  11. printf("Sou um Processo.\n");
  12. printf("Sou o processo %d \n", getpid());
  13. int pidpapa = getpid();
  14. int pidavo =getppid();
  15. //char[] time = system("date +%T;");
  16. const time_t timer1 = time(NULL);
  17. struct tm * ptm1;
  18. ptm1=gmtime(&timer1);
  19.  
  20. filho1=fork();
  21.  
  22.  
  23. if(pidpapa==getpid())
  24. {
  25.  
  26. printf("Filho %d sou o pai %d, são %d:%d:%d?\n \n",filho1,getpid(),ptm1->tm_hour%24,ptm1->tm_min,ptm1->tm_sec);
  27. }
  28.  
  29. sleep(3);
  30.  
  31. if(0 == filho1)
  32. {
  33. const time_t timer1 = time(NULL);
  34. struct tm * ptm1;
  35. ptm1=gmtime(&timer1);
  36. printf("Pai %d sou o filho %d, confirmo são %d:%d:%d \n \n",getppid(),getpid(),ptm1->tm_hour%24,ptm1->tm_min,ptm1->tm_sec);
  37. }
  38.  
  39. sleep(3);
  40.  
  41. if(pidpapa==getpid())
  42. {
  43. filho2=fork();
  44. }
  45.  
  46. if(pidpapa==getpid())
  47. {
  48. const time_t timer1 = time(NULL);
  49. struct tm * ptm1;
  50. ptm1=gmtime(&timer1);
  51. printf("Filho %d sou o pai %d, são %d:%d:%d?\n \n",filho2,getpid(),ptm1->tm_hour%24,ptm1->tm_min,ptm1->tm_sec);
  52. sleep(4);
  53. }
  54.  
  55. sleep(3);
  56.  
  57. if(filho2==0)
  58. {
  59. const time_t timer1 = time(NULL);
  60. struct tm * ptm1;
  61. ptm1=gmtime(&timer1);
  62. printf("Pai %d sou o filho %d, confirmo são %d:%d:%d \n \n",getppid(),getpid(),ptm1->tm_hour%24,ptm1->tm_min,ptm1->tm_sec);
  63. }
  64.  
  65. }
Add Comment
Please, Sign In to add comment