Reputation: 355
I have a key for message queue inter process communication, say key_t = 10
.
I want to get the queue ID if message queue already exist with key value 10.
Currently I am using below code to find the queue is exist or not using return error
msgget((key_t)10,IPC_EXCL|IPC_CREAT|0777)
but I want to get queue ID and need to close it.
Upvotes: 0
Views: 1861
Reputation: 14949
You can use msgget
without using IPC_EXCL
flag to get existing message queue identifier.
mid = msgget((key_t)10, 0);
Then, using that identifier you can use remove the message queue by using msgctl
with IPC_RMID
flag.
EDIT:
key_t ftok(char *pathname, char proj_id);
Upvotes: 1