'why semop() function call is not working?
semop function call is not working on the linux .I am running this program on 2 terminals so what I am trying to do is that allowing one instance of program into critical section from one terminal and another instance from terminal 2 will wait before critical section till first comes out, but semop is not working so both are entering into the critical section at the same time ,so what i am missing here , can anybody resolve this issue?
#include<stdio.h>
#include<unistd.h>
#include<sys/sem.h>
#include<sys/types.h>
#include<sys/ipc.h>
int main(void)
{
int key,semid;
key=ftok(" ",'a');
struct sembuf buf={0,-1,0};
semid= semget(key,1,0);
printf("Before entering into the critical section\n");
printf("Waiting for unlock\n");
semop(semid, &buf,1);
printf("Enter the critical section\n");
printf("Enter to unlock\n");
getchar();
buf.sem_op=1;
semop(semid, &buf,1);
}```
Solution 1:[1]
I think you need to add another getchar() under the already existing one.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Teja |
