Driver_code.c # include <Stdio. h> # Include <Stdlib. h> # Include <Unistd. h> # Include <Sys/types. h> # Include <Fcntl. h> # Include <Semaphore. h> Char Sem_name1 [] = " Sem1 " ; Char Sem_name2 [] = " Sem2 " ; Int Main (){ Int I; sem_t * Sem1; sem_t * Sem2; sem1 = Sem_open (sem_name1, o_creat, 0644 , 0 ); If (Sem1 = Sem_failed) {perror ( " Unable to create semphore " ); Sem_unlink (sem_name1); exit ( - 1 );} Sem2 = Sem_open (sem_name2, o_creat, 0644 , 0 ); If (Sem2 = Sem_failed) {perror ( " Unable to create semphore " ); Sem_unlink (sem_name2); exit ( - 1 );} For (I = 0 ; I < 5 ; I ++ ) {Sem_wait (sem1); printf ( " Driver: Drive \ n " ); Sleep ( 5 ); Printf ( " Driver: Stop \ n " ); Sleep ( 2 ); Sem_post (sem2);} sem_close (sem1); sem_close (sem2); sem_unlink (sem_name1); sem_unlink (sem_name2); exit ( 0 );} Sales_code.c # include <Stdio. h> # Include <Stdlib. h> # Include <Unistd. h> # Include <Sys/types. h> # Include <Fcntl. h> # Include <Semaphore. h> Char Sem_name1 [] = " Sem1 " ; Char Sem_name2 [] = " Sem2 " ; Int Main (){ Int I; sem_t * Sem1; sem_t *Sem2; sem1 = Sem_open (sem_name1, 0 , 0644 , 0 ); If (Sem1 = Sem_failed) {perror ( " Unable to create semphore " ); Sem_unlink (sem_name1); exit ( - 1 );} Sem2 = Sem_open (sem_name2, 0 , 0644 , 0 ); If (Sem2 = Sem_failed) {perror ( " Unable to create semphore " ); Sem_unlink (sem_name2); exit ( - 1 );} For (I = 0 ; I < 5 ; I ++) {Printf ( " Seller: Close door. \ n " ); Sleep ( 1 ); Sem_post (sem1); sleep ( 2 ); Printf ( " Seller: vendor. \ n " ); Sem_wait (sem2); printf ( " Seller: open and let out or in. \ n " ); Sleep ( 3 );} Sem_close (sem1); sem_close (sem2 ); /* Sem_unlink (sem1); sem_unlink (sem2 ); */ Exit ( 0 );}