sh cleanipc进程间通讯资源释放(清理)Shell脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh cleanipc进程间通讯资源释放(清理)Shell脚本相关的知识,希望对你有一定的参考价值。
#!/bin/bash
#check pramrs num
if (($# != "2"))
then
echo -e "paramrs error\nuse: $0 [username] [shm|sem|msg|all]"
exit
elif (($2!="shm" && $2!="sem" && $2!="msg" && $2!="all"))
then
echo -e "paramrs error\nuse: $0 [username] [shm|sem|msg|all]"
exit
fi
#delete shm
if (($2=="shm" || $2=="all"))
then
START=$(ipcs|sed -n '/Shared/=')
END=$(ipcs|grep -n "^[/s]*$"|awk -F: '{if($1>'"$START"') print $1}'|head -1)
for i in $(ipcs|sed -n ${START},${END}p|grep $1|awk '{print $2}')
do
ipcrm shm $i
echo "shm: $i"
done
echo "delete shm complete."
fi
#delete sem
if (($2=="sem" || $2=="all"))
then
START=$(ipcs|sed -n '/Semaphore/=')
END=$(ipcs|grep -n "^[/s]*$"|awk -F: '{if($1>'"$START"') print $1}'|head -1)
for i in $(ipcs|sed -n ${START},${END}p|grep $1|awk '{print $2}')
do
ipcrm sem $i
echo "sem: $i"
done
echo "delete sem complete."
fi
#delete msg
if (($2=="msg" || $2=="all"))
then
START=$(ipcs|sed -n '/Message/=')
END=$(ipcs|grep -n "^[/s]*$"|awk -F: '{if($1>'"$START"') print $1}'|head -1)
for i in $(ipcs|sed -n ${START},${END}p|grep $1|awk '{print $2}')
do
ipcrm msg $i
echo "msg: $i"
done
echo "delete msg complete."
fi
以上是关于sh cleanipc进程间通讯资源释放(清理)Shell脚本的主要内容,如果未能解决你的问题,请参考以下文章
进程和线程的关系及区别,进程间如何通讯,线程间如何通讯
C# kill线程正常释放资源?
异常进程终止时的资源清理
进程间的通讯(IPC)方式
进程间的通讯(IPC)方式
利用QSystemSemaphore和QSharedMemory实现进程间通讯