#!/bin/bash if [ $# -lt 1 -o $# -gt 2 ] then echo "参数个数不正确!" exit -1 fi WHOAIM=`whoami` function release { if [ $1 -le $2 ] then for id in `ipcs | sed -n $1,$2p | grep "${WHOAMI}" | awk '{print $2}'` do ipcrm $3 $id done fi } function releasebyid { ipcrm $1 $2 } function judgetype { case $1 in "shm") start=$((`ipcs | sed -n '/shmid/='`+1)) end=$((`ipcs | sed -n '/Semaphore/='`-1)) if [ $# -eq 2 ] then releasebyid "-m" $2 else release $start $end "-m" fi ;; "sem") start=$((`ipcs | sed -n '/semid/='`+1)) end=$((`ipcs | sed -n '/Message/='`-1)) if [ $# -eq 2 ] then releasebyid "-s" $2 else release $start $end "-s" fi ;; "msg") start=$((`ipcs | sed -n '/msqid/='`+1)) end=$((`ipcs | sed -n '$='`-1)) if [ $# -eq 2 ] then releasebyid "-q" $2 else release $start $end "-q" fi ;; *) echo "错误的参数 [shm] [sem] [msg] [all]" exit 0 ;; esac } if [ "$1" = "all" ] then if [ $# -eq 2 ] then echo "[all]不可以有第二个参数!" exit 0 else judgetype "shm" judgetype "sem" judgetype "msg" fi else judgetype $1 $2 fi echo "shell执行成功!"