Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include "semaphor.h"
- void sectionCritique(int);
- int sem;
- int main (int argc, char * argv[]){
- sem=ouvrirsem(123);
- initsem(sem,2);
- if (fork() == 0){
- sectionCritique(1);
- }
- if (fork() == 0){
- sectionCritique(2);
- }
- if (fork() == 0){
- sectionCritique(3);
- }
- if (fork() == 0){
- sectionCritique(4);
- }
- wait(0);
- supsem(sem);
- return 0;
- }
- void sectionCritique(int nb){
- down(sem);
- printf("%d\n", nb);
- //write(1, "prout", 2);
- //fprintf(stdout, "%s", "A");
- //fflush(stdout);
- up(sem);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement