Bash shell script for killing ipc objects

Bash shell script for killing ipc objects

Post by Richard Aleksand » Sat, 09 Oct 1999 04:00:00



Hi Folks,

I am trying to write a script with which I can remove any semaphores,
message queues,
and shared mem segs that I (a non-root user) have allocated. The closest
I have to working is the following, which spits out lots of warnings and
doesn't work

#!/bin/csh

if ($#argv == 0) then
  ipcs | xargs kipc
else
  set I = 0
  foreach J ($*)
    if ($I == m) ipcrm shm $J
    if ($I == q) ipcrm msg $J
    if ($I == s) ipcrm sem $J
    set I = $J
  end
endif

Help, please!!

 
 
 

Bash shell script for killing ipc objects

Post by James A. Robinso » Tue, 12 Oct 1999 04:00:00


Quote:> I am trying to write a script with which I can remove any semaphores,
> message queues, and shared mem segs that I (a non-root user) have
> allocated. The closest I have to working is the following, which spits
> out lots of warnings and doesn't work

Here's a first stab at it. It appears to do what you want (I just
tested it on my linux box, so I don't know about other OSs ipcs/ipcrm
formats).

    #!/bin/sh

        for flag in m q s
        do
                for id in `ipcs -$flag | egrep -v '^(-----|key|$)' | cut -d' ' -f2`
                do
                        case $flag in
                                m)
                                        type=shm
                                        ;;
                                q)
                                        type=msg
                                        ;;
                                s)
                                        type=sem
                                        ;;
                        esac
                        if [ "$type" != "" ] && [ $id -gt 1 ]; then
                                ipcrm $type $id
                        fi
                done
        done

 Sent via Deja.com http://www.deja.com/
 Before you buy.