Linux – How to remove all the IPC-Message queue

cipclinuxunix

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?

Best Answer

ipcrm can do just that:

ipcrm --all=msg

Instead of msg you can use sem and shm for semaphores and shared memory.