Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <sys/wait.h>
  7.  
  8. void sigusr1(int sig, siginfo_t *info, void *extra)
  9. {
  10. void *ptr = info->si_value.sival_ptr;
  11. printf("1\n");
  12. }
  13. void firstProcess()
  14. {
  15. struct sigaction action;
  16. action.sa_flags = SA_SIGINFO;
  17. action.sa_sigaction = &sigusr1;
  18.  
  19. sigset_t oldset;
  20. sigemptyset(&action.sa_mask);
  21. sigaddset(&action.sa_mask, SIGUSR1);
  22. sigemptyset(&oldset);
  23. sigprocmask(SIG_BLOCK, &action.sa_mask, &oldset);
  24. if (sigaction(SIGUSR1, &action, 0) == -1) {
  25. exit(1);
  26. }
  27. int sig = 0;
  28. sigwait(&action.sa_mask, &sig);
  29. printf("%d\n", sig);
  30. exit(0);
  31. }
  32.  
  33. void secondProcess()
  34. {
  35. int i;
  36. exit(0);
  37. }
  38. int main(int argc, char *argv[])
  39. {
  40. pid_t pid1, pid2, pid3;
  41. pid_t *arrpid;
  42. pid1 = fork();
  43.  
  44. struct sigaction actStc;
  45. memset(&actStc, 0, sizeof(actStc));
  46. // actStc.sa_handler = firsthdl;
  47. //sigset_t set;
  48. sigemptyset(&actStc.sa_mask);
  49. sigaddset(&actStc.sa_mask, SIGUSR1);
  50. sigaction(SIGUSR1, &actStc, 0);
  51. //wait(NULL);
  52. // printf("%ld\n", strlen(argv[1]));
  53. if (pid1 == 0) {
  54. firstProcess();
  55. } else {
  56. sleep(1);
  57. union sigval sigUn;
  58. sigUn.sival_ptr = argv[1];
  59. sigqueue(pid1, SIGUSR1, sigUn);
  60. // kill(pid1, SIGUSR1);
  61. pid2 = fork();
  62. if (pid2 == 0) {
  63. secondProcess();
  64. } else {
  65. pid3 = fork();
  66. if (pid3 == 0) {
  67. //for ( ; ; );
  68. } else {
  69. //sleep(10);
  70. }
  71. }
  72. }
  73. //printf("%d\n", getSig);
  74. sleep(1);
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement