如何删除所有 IPC-Message 队列?

Bhu*_*esh 2 c unix linux ipc

考虑我使用 msgget() 函数创建了 100 个消息队列。

 ------ 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        
....
.....
....
Run Code Online (Sandbox Code Playgroud)

使用一个ipcrm命令,我们可以一次删除单个队列。

ipcrm -q queue_id
Run Code Online (Sandbox Code Playgroud)

或者使用 amsgctl()我们可以删除它。但我想一次性删除所有消息队列。有没有办法在linux中做到这一点?

小智 5

ipcrm 可以做到这一点:

ipcrm --all=msg
Run Code Online (Sandbox Code Playgroud)

您可以将 sem 和 shm 用于信号量和共享内存,而不是 msg。