zoukankan      html  css  js  c++  java
  • Linux shell实战(ipcs工具)

    #!/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执行成功!"
  • 相关阅读:
    C#处理json实战
    HDU3994(Folyd + 期望概率)
    POJ1270 Following Orders (拓扑排序)
    HDU 3634 City Planning (离散化)
    HDU4762(JAVA大数)
    POJ3026(BFS + prim)
    POJ1679(次小生成树)
    UVA10487(二分)
    ZOJ 2048(Prim 或者 Kruskal)
    FZU 1856 The Troop (JAVA高精度)
  • 原文地址:https://www.cnblogs.com/zhanggaofeng/p/6113199.html
Copyright © 2011-2022 走看看