日期:2014-05-16  浏览次数:20786 次

求帮助!
想写一个shell,根据查询出的shmid 来杀掉相应的进程
[root@Sender2 ~]# ipcs -m

------ Shared Memory Segments --------
key shmid owner perms bytes nattch status  
0x010320fc 393216 root 666 2588160 2  
0x01032393 425985 root 666 2588160 2  
0x000320fc 458754 root 666 35716608 2  
0x00032393 491523 root 666 35716608 2  
0x650320fc 524292 root 666 67292160 2  
0x65032393 557061 root 666 67292160 2  
0x660320fc 589830 root 666 32093184 2  
0x66032393 622599 root 666 32093184 2  
0x670320fc 655368 root 666 7246848 2  
0x67032393 688137 root 666 7246848 2  
0x680320fc 720906 root 666 517632 2  
0x68032393 753675 root 666 517632 2  
0x690320fc 786444 root 666 8282112 2  
0x69032393 819213 root 666 8282112 2  

[root@Sender2 ~]#ipcrm shm 392316

ipcrm shm 命令只能一条一条的删,而且每次启动后,这些shmid还会变,有能帮我的么?

------解决方案--------------------
PHP code
[User:root Time:20:23:11 Path:/home/liangdong/shell]$ cat test.sh 
#!/bin/sh 

function ipc_remove() {
        row=0;
        ipcs -$1 | grep -v ^$ | while read line; do 
                if [ "$row" -ge "2" ];then
                        echo $line;
                        shmid=`echo $line | awk '{print $2}'`;
                        if [ "$shmid" -ne "0" ];then
                                ipcrm -$1 $shmid
                        fi
                fi
                let row=$row+1
        done
}

ipc_remove "m";
ipc_remove "s";
ipc_remove "q";

------解决方案--------------------
试试
ipcs -m | awk '$1~/0x/ {print "ipcrm -M", $1}' | sh