Recently i came across this exercise that for some reason always gives me strange output, here is the code followed by an output example:
HERE'S THE CONSUMER PROCESS
os@debian:~/Esercizi/semafori/libreria$ ./consumator
Ciao, ciao e ciao // i wrote it using productor process
// i didn't
Mia, mio e miei //i wrote it
o //i didn't
//i didn't
Ok ora basta. //i wrote it
i //i didn't
o //i didn't
I tried executing the 2 processes multiple times and each time they gave me a different strange output.
Recently i came across this exercise that for some reason always gives me strange output, here is the code followed by an output example: HERE'S THE CONSUMER PROCESS [code]#include #include #include #include #include #include "sem.h"
while(running){ if(SEM_P(WRITE_ID) == -1) exit(EXIT_FAILURE); //aspetto il via alla scrittura fd = open(nome_file, O_CREAT | O_TRUNC | O_WRONLY, 0660); printf("Write on your file:\n"); fgets(buffer, sizeof(buffer), stdin); write(fd, buffer, strlen(buffer)); if(strncmp(buffer, "end", 3) == 0){ running = 0; } close(fd); if(SEM_V(READ_ID) == -1) exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); }
[/code] HERE'S THE CONSUMATOR OUTPUT: [code]os@debian:~/Esercizi/semafori/libreria$ ./consumator Ciao, ciao e ciao // i wrote it using productor process // i didn't Mia, mio e miei //i wrote it o //i didn't //i didn't Ok ora basta. //i wrote it i //i didn't o //i didn't
[/code] I tried executing the 2 processes multiple times and each time they gave me a different strange output.