Semaphore semget method return value confirmation


I want to get a same semId using same key.
Although, I called semget method using same key, and returned different semId.

Please answer me the reason why this problem happened.

Sample source :

int id1, id2;
int semflg = IPC_CREAT | 0666;
id1 = semget(0, 1, semflg);
id2 = semget(0, 1, semflg);

Result : id1 != id2


I think you need to add some tags to this question, since semget is not part of the C language.
@shlim what are the value of id1 and id2? Did you checked that none is having value -1?
id1, id2 value is some value which registed in IPC semaphore for example id1 = 786432, id2 = 819201
– shlim
9 hours ago



Key id 0 is IPC_PRIVATE, and will always generate a new set of semaphores. Choose a valid key.


Thank you. I didn’t think that IPC_PRIVATE was 0. T.T
– shlim
9 hours ago