Delete all SYSTEM V shared memory and semaphores on UNIX-like systems

前端 未结 11 2489
情话喂你
情话喂你 2020-12-23 14:01

How can I delete all not used semaphores and shared memory with a single command on a UNIX-like system, e.g., Ubuntu?

11条回答
  •  悲&欢浪女
    2020-12-23 14:58

    1 line will do all

    For message queue

    ipcs -q | sed "$ d; 1,2d" |  awk '{ print "Removing " $2; system("ipcrm -q " $2) }'
    

    ipcs -q will give the records of message queues

    sed "$ d; 1,2d " will remove last blank line ("$ d") and first two header lines ("1,2d")

    awk will do the rest i.e. printing and removing using command "ipcrm -q" w.r.t. the value of column 2 (coz $2)

提交回复
热议问题