Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include "semaphor.h"
  5.  
  6. void sectionCritique(int);
  7.  
  8. int sem;
  9.    
  10.  
  11. int main (int argc, char * argv[]){
  12.     sem=ouvrirsem(123);
  13.     initsem(sem,2);
  14.    
  15.    
  16.    
  17.     if (fork() == 0){
  18.        
  19.         sectionCritique(1);
  20.        
  21.     }
  22.    
  23.     if (fork() == 0){
  24.        
  25.         sectionCritique(2);
  26.        
  27.     }
  28.    
  29.     if (fork() == 0){
  30.        
  31.         sectionCritique(3);
  32.        
  33.     }
  34.    
  35.     if (fork() == 0){
  36.        
  37.         sectionCritique(4);
  38.        
  39.     }
  40.     wait(0);
  41.     supsem(sem);
  42.     return 0;
  43. }
  44.  
  45. void sectionCritique(int nb){
  46. down(sem); 
  47.   printf("%d\n", nb);
  48. //write(1, "prout", 2);
  49. //fprintf(stdout, "%s", "A");
  50. //fflush(stdout);
  51.   up(sem);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement