Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h> //fork
  4. #include <sys/wait.h> //waitpid
  5. #include <signal.h>
  6. #include <string.h>
  7.  
  8. void handler(int signumber){
  9. printf("Signal with number %i has arrived\n",signumber);
  10. }
  11.  
  12. int main() {
  13. int fd1[2]; // Used to store two ends of first pipe
  14.  
  15. char fixed_str[] = "forgeeks.org";
  16. char input_str[] = "kurva";
  17. signal(SIGUSR1, handler);
  18. char sz[100];
  19. printf("Mentőexpedíció indul\n");
  20. pid_t child = fork();
  21. if (child>0) //the parent process
  22. {
  23. printf("Szülő: Var gyerekre \n");
  24. pause();
  25. printf("Szülő: Signal megerkezett %i\n", SIGUSR1);
  26.  
  27. printf("Szülő: Ir a csovezetkbe \n");
  28.  
  29. close(fd1[0]);
  30. write(fd1[1], "Hajra Fradi!\0",15);
  31. close(fd1[1]);
  32.  
  33. printf("Szulo beirta az adatokat a csobe!\n");
  34.  
  35. int status;
  36. wait(&status);
  37. printf("Szülő: befejezodott \n");
  38.  
  39. }
  40. else //child process
  41. {
  42. printf("Gyerek: Elindult... \n");
  43. sleep(3);
  44. printf("Gyerek: Odaert... \n");
  45. printf("Gyerek: Signal kuldese... \n");
  46. kill(getppid(), SIGUSR1);
  47. printf("Gyerek: Signal elkuldve... \n");
  48.  
  49. printf("Gyerek: Var a pipe uzenetre... \n");
  50. sleep(3);
  51. printf("Gyerek: elkezdi olvasni a csobol az adatokat!\n");
  52. close(fd1[1]); // Close writing end of first pipe
  53. // Read a string using first pipe
  54. char concat_str[100];
  55. read(fd1[0], concat_str, 100);
  56. printf("Gyerek: olvasta: %s\n", concat_str);
  57. close(fd1[0]);
  58.  
  59. }
  60. return EXIT_SUCCESS;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement