Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1.  
  2.  
  3. #include <pthread.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include "string.h"
  7. #include <unistd.h>
  8. #include <fcntl.h>
  9. #include <signal.h>
  10.  
  11.  
  12. void HandlerInt(int signal)
  13. {
  14.  
  15.  
  16. }
  17.  
  18. void* Fct(void* p)
  19. {
  20.  
  21.  
  22. int nombre = *((int *)p);
  23.  
  24. printf("Pid : %u Sequence : %d \n\n", getpid(),nombre);
  25.  
  26. pause();
  27.  
  28. printf("Pid : %u.%d terminé\n\n", getpid(),nombre);
  29. fflush(stdout);
  30. pthread_exit(0);
  31. }
  32.  
  33. int main()
  34. {
  35.  
  36. int * ret, param = 0,param1=1, param2 = 2, param3 = 3;
  37.  
  38. struct sigaction sig;
  39.  
  40. sig.sa_handler = HandlerInt;
  41. sigemptyset(&sig.sa_mask);
  42. sigaction(SIGINT, &sig, NULL);
  43.  
  44. pthread_t tid,tid1,tid2,tid3;
  45.  
  46. pthread_create(&tid,NULL,Fct,&param);
  47.  
  48.  
  49. pthread_create(&tid1,NULL,Fct,&param1);
  50.  
  51.  
  52. pthread_create(&tid2,NULL,Fct,&param2);
  53.  
  54.  
  55. pthread_create(&tid3,NULL,Fct,&param3);
  56.  
  57.  
  58. pause();
  59.  
  60. printf("Main Terminé\n\n");
  61. fflush(stdout);
  62. pthread_exit(NULL);
  63.  
  64.  
  65. return 1;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement