Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4. #include <unistd.h>
  5. #include <signal.h>
  6.  
  7. void oldman() {
  8. fprintf(stdout, "I'm not yet dead! My ID is %i\n", (int)getpid());
  9. }
  10.  
  11. void recreation() {
  12. fprintf(stdout, "Who I am? My ID is %i\n", (int)getpid());
  13. }
  14.  
  15. int main() {/*
  16. pid_t child_pid, parent_pid;
  17. int i = 0;
  18. fprintf(stdout,"Before RECREATION %i\n",parent_pid = (int)getpid());
  19. child_pid = fork();
  20. while(i++ < 5)
  21. if (child_pid!=0)
  22. oldman();
  23. else recreation();*/
  24. pid_t child_pid, parent_pid;
  25. double s = 0.0;
  26. parent_pid = (int)getpid();
  27. child_pid = fork();
  28. fork();
  29. fork();
  30. //kill(child_pid, SIGKILL);
  31. fprintf(stdout, "PARENT: %i\nCHILD: %i\n", parent_pid, child_pid);
  32. pause();
  33.  
  34. if(child_pid != parent_pid) {
  35. s += 3.14;
  36. fprintf(stdout, "CHILD: %i s=%g &s=%f\n", (int)getpid(), s, &s);
  37. }else
  38. {
  39. s += 2.72;
  40. fprintf(stdout, "PARENT: %i s=%g &s=%f\n", (int)getpid(), s, &s);
  41. }
  42. return (EXIT_SUCCESS);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement