process semaphores linux - wait
Posted
by coubeatczech
on Stack Overflow
See other posts from Stack Overflow
or by coubeatczech
Published on 2010-05-03T14:54:00Z
Indexed on
2010/05/03
14:58 UTC
Read the original article
Hit count: 280
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?
© Stack Overflow or respective owner