Reputation: 1279
Consider I have created a 100 messages queues using a msgget() function.
------ Message Queues --------
key msqid owner perms used-bytes messages
0x00000000 262144 bhuvaneshw 666 40 2
0x00000000 294913 bhuvaneshw 666 40 2
0x00000000 327682 bhuvaneshw 666 40 2
0x00000000 360451 bhuvaneshw 666 40 2
0x00000000 393220 bhuvaneshw 666 40 2
0x00000000 425989 bhuvaneshw 666 55 3
....
.....
....
Using a ipcrm
command we can remove the single queue at a time.
ipcrm -q queue_id
or else using a msgctl()
we can remove that. But I want to remove all the message queues in single instant . Is there is any way to do this in linux?
Upvotes: 2
Views: 30196
Reputation: 51
ipcrm can do just that:
ipcrm --all=msg
Instead of msg you can use sem and shm for semaphores and shared memory.
Upvotes: 5
Reputation: 744
Hey I got you the answer
you can delete message queue's using KEY number running in loop from starting to max range(use system() function),
but message Queue with KEY=0, cannot be removed in that way
->" ipcrm -Q 0
" not possible,
so better way is to get mesQid for each key, then use msgctl(msgQid,IPC_RMID,0);
in this way you can remove with key=0 also;
so problem sums up to get msgqid by avoiding msgget() (read MSG_INFO and MSG_STAT from $man 2 msgctl)
so now,
loop over the kernel's index system for active message queues,
then get the msgqid using sequential index and looping
i.e msqid = msgctl(ind, MSG_STAT, &ds)
, so thats it.
for cleaner understanding read through MSG_INFO and MSG_STAT from
$man 2 msgctl
.
or a cleaner code i tried here and working https://github.com/chetanDN/linux-system-programming/blob/master/IPC/messageQ/2.deleteMsgQ/deleteAllCurrentMsgQs.c
Upvotes: 1
Reputation: 4041
Try this one,
ipcrm -q 262144 -q ... -q ...
You can give like this. Option is must.
Upvotes: 0
Reputation: 8280
There is an option -Q
in ipcrm
that deletes all the messages in the queue.
For instance, ipcrm -Q 0x00000000
deletes all the messages for the key 0x00000000
Upvotes: 1