Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1.  
  2. /*
  3. *
  4. * Napisać program obsługujący sygnały czasu rzeczywistego
  5. * minimum to:
  6. * Wyświetlenie komunikatu: "dostałem sygnał taki i taki"
  7. * Dodatkowe wymogi
  8. * musi umieć odebrać dane przekazane od sygnału
  9. * musi umieć przetwarzać przynajmniej (ale może też więcej) 2 różne sygnały
  10. * obsługa sygnału ma być osługą synchroniczną (przynajmniej 3 wątki)
  11. * (ad1. w tym 1 wątek macierzysty i 2 wątki do obsługi sygnału)
  12. * napisać własną komende kill która umożliwi wysłanie sygnału z danymi
  13. *
  14. * sigfill
  15. * siempty
  16. * sigaddset
  17. * sigdelset
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <pthread.h>
  23. #include <signal.h>
  24.  
  25. int sig1, sig2;
  26.  
  27. //SIGFPE
  28. void* thread1_func(void * arg){
  29. printf("Read thread 1");
  30.  
  31. int sigwait( SIGFPE, &sig1 );
  32. printf("end read thread 1");
  33. }
  34.  
  35. //SIGINT
  36. void* thread2_func(void * arg){
  37. printf("Read thread 2");
  38.  
  39. int sigwait( sigsetmask(SIGINT), &sig2 );
  40. printf("end read thread 2\n");
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47. int main(void) {
  48. puts("Starting program");
  49.  
  50. pthread_t thread;
  51. pthread_create( &thread, NULL, &thread1_func, NULL );
  52. pthread_create( &thread, NULL, &thread2_func, NULL );
  53.  
  54. int time = 360;
  55. for(int i = 0; i < time; i++){
  56. printf("%d\n",i);
  57. sleep(1);
  58. }
  59.  
  60. return EXIT_SUCCESS;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement