rendered paste body#include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/sem.h> int main(void) { key_t key; int semid;static struct sembuf DecrR = {0,-1,SEM_UNDO};static struct sembuf IncrR = {0,1,SEM_UNDO};static struct sembuf DecrW = {1,-1,SEM_UNDO};static struct sembuf IncrW = {1,1,SEM_UNDO};static struct sembuf DecrCl = {2,-1,SEM_UNDO};static struct sembuf IncrCl = {2,1,SEM_UNDO};static struct sembuf DecrC = {3,-1,SEM_UNDO};static struct sembuf IncrC = {3,1,SEM_UNDO}; key = ftok("reader.c", 'X'); semid= semget(key,4,IPC_CREAT | 0600);// semctl(semid,0,SETVAL,1);// semctl(semid,1,SETVAL,1);// semctl(semid,2,SETVAL,1);// semctl(semid,3,SETVAL,1);int i;int j;for(i = 0; i<5; i++){semop(semid,&IncrR,1);semctl(semid,2,SETVAL,0);j=semctl(semid, 3, GETVAL, 0);if(j==0){semctl(semid,1,SETVAL,0);semop(semid, &IncrC, 1);}semctl(semid,2,SETVAL,1);semop(semid, &DecrR, 1);printf("READING\n");sleep(2);printf("DONE READING\n");semctl(semid,2,SETVAL,0);semop(semid, &DecrC, 1);j=semctl(semid, 3, GETVAL, 0);if(j==0){semctl(semid,1,SETVAL,1);semop(semid, &DecrCl, 1);}sleep(4);} return 0; }