I've set(semget + init to 1) a semaphore in process A. Forked A, and got B.
Forked B and got C (code of processes B,C is at another .c file, so I am passing the semid as a global integer with extern int semid).
Into the process C code, I try to apply down(semid) and getting "invalid argument" error.
What I am doing in the code for down function is this:
struct sembuf sem_d;
sem_d.sem_num = 0;
sem_d.sem_op = -1;
sem_d.sem_flg = 0;
if ( semop(semid, &sem_d, 1) == -1 )
{
perror("error with down function");
return -1;
}
What am I doing wrong?
I've also have reassured that the semid from when the semaphore is initialized is the same before semop.
Also, in process A,B I am using wait(-1).