Rainbow_Helicopter

Задание #1.2. SigTrap

Jan 14th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. //~ Написать программу на СИ, обрабатывающую каждое четное возникновение
  2. //~ сигнала SIGTRAP формированием двух сыновних процессов, связанных каналом.
  3. //~ ---------------------------------------------------------------
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <sys/types.h>
  9. #include <fcntl.h>
  10. #include <signal.h>
  11. #include <string.h>
  12.  
  13. void TrapHandler(int SigN);
  14.  
  15. int count=0; //переменная четности получения сигнала
  16.  
  17. int main(int argc, char**argv)
  18. {
  19.     signal(SIGTRAP,TrapHandler);
  20.     for(;;);
  21.     return 0;
  22. }
  23.  
  24. void TrapHandler(int Sign)
  25. {
  26.     int PD[2];
  27.    
  28.     signal(SIGTRAP,TrapHandler);
  29.     count++;   
  30.     if(count%2==0)
  31.     {
  32.     pipe(PD);
  33.     if (fork()) //предок
  34.         if (fork()) //предок
  35.             { close(PD[0]); close(PD[1]); }
  36.         else //дочерний процесс #1
  37.             for(;;);
  38.     else //дочерний процесс #2
  39.         for(;;);
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment