Advertisement
Guest User

Untitled

a guest
May 17th, 2015
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #define _SVID_SOURCE
  2. #include<sys/types.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include<sys/ipc.h>
  6. #include <sys/wait.h>
  7. #include<sys/sem.h>
  8. #include <unistd.h>
  9. #include "semafory.h"
  10.  
  11.  
  12. int main()
  13. {
  14.  
  15. int licznikProcesow;
  16. printf("Podaj ilość procesów dla powielacza\n");
  17. scanf("%d",&licznikProcesow);
  18. key_t key;
  19. key=uzDostep();
  20. int idZestawu=tworzenie(key);
  21. printf("semafor utworzony\n");
  22. inicjalizacja(idZestawu);
  23. int i=0;
  24.  
  25. while(i<licznikProcesow)
  26. { pid_t pid=fork();
  27. if( pid==-1)
  28. {
  29.  
  30. perror("błąd fork\n");
  31. exit(1);
  32. }
  33. if(pid== 0) //proces potomny
  34. {
  35. printf("proces nr:%d",getpid());
  36. execl("./semafory.exe","semafory.exe",NULL);
  37. perror("execl error\n");
  38. }
  39. else
  40. { sleep(4); //proces macierzysty
  41.  
  42. }
  43. i++;
  44. }
  45. int ileProcesow;
  46. ileProcesow=kolejka(idZestawu);
  47. if(ileProcesow<1)
  48. { usunSem(idZestawu);
  49. }
  50. fprintf(stdout,"Koniec\n");
  51. return 0;
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement