Semctl system call gives Segmentation Fault

cajus.hahn at cajus.hahn at
Wed Dec 3 18:06:18 EST 2003


I have the same problem.
It looks like a problem with the glibc.
My gdb reports:
"Program receives signal SIGSEGV, Segmentation fault.
0x0ff890f4 in semctl() from lib/"

I tried to find out what is happening:
semctl() takes three or  four parameters:
semctl( int semid, int semnum, int cmd, arg)
where "arg"  should be optional depending on the command "cmd".

a) you always need four parameters, if you do not provide parameter #4 you
int dummy;
value=semctl(semaphore_id, 0, GETVAL);   /* you get SIGSEGV ! */
value=semctl(semaphore_id, 0, GETVAL,&dummy);   /* works */
semctl(semaphore_id, 0, IPC_RMID);  /* you get SIGSEGV ! */
semctl(semaphore_id, 0, IPC_RMID, &dummy);  /* works  */

b) "arg" needs to be a pointer, even for commands that do not really use
parameter #4 !
semctl(semaphore_id, 0, SETVAL, init_val);   /* you get SIGSEGV ! */
semctl(semaphore_id, 0, SETVAL, &init_val);   /* works !!! */

Using a pointer for the value in SETVAL is only a workaround !
Keep this in mind, if you are changing to a new (correct working) glibc!


** Sent via the linuxppc-embedded mail list. See

More information about the Linuxppc-embedded mailing list