process semaphores linux - wait
- by coubeatczech
Hi, I try to code a simple program that starts and waits on the system semaphore until it gets terminated by signal.
union semun {
int val;
struct semid_ds *buf;
unsigned short int *array;
struct seminfo *__buf;
};
int main(){
int semaphores = semget(IPC_PRIVATE,1,IPC_CREAT | 0666);
union semun arg;
arg.val = 0;
semctl(semaphores,0,SETVAL,arg);
struct sembuf operations[1];
operations[0].sem_num = 0;
operations[0].sem_op = -1;
operations[0].sem_flg = 0;
semop(semaphores,operations,1);
fprintf(stderr,"Why?\n");
return 0;
}
I expect, that everytime this program gets executed, nothing actually happens and it waits on the semaphore, but everytime it goes through the semaphore and writes Why?. Why?