1828161 Members
2435 Online
109975 Solutions
New Discussion

ipcs in awk-script

 
SOLVED
Go to solution
Inesa Clinko
Advisor

ipcs in awk-script

Please help me:
I want to find unused shared memory resources with "ipcs -smo" and remove it with "ipcrm", using awk-script from command line. If it needed, I can use temp.file.

Please show me an example.

Regards,Inesa
4 REPLIES 4
Steven E. Protter
Exalted Contributor
Solution

Re: ipcs in awk-script

Hello Inesa,

ipcs -smo | grep | > /tmp/temp.file

while read a b c
do
ipcrm "-$a $c"
done < /tmp/temp.file

SEP

Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
A. Clay Stephenson
Acclaimed Contributor

Re: ipcs in awk-script

Be care using this, NATTCH = 0 is a necessary but not necessarily sufficient condition for the removal of a shared memory identifier. It all depends upon how the software that uses the shared memory was written. For example, it is not unusual for an initialization program to run and setup a shared memory segment and then detach and exit. In that case, NATTCH = 0 but additional programs could run later expecting that shared memory identifier to be available and crash. This is a fairly common method for programs that might require long initializations otherwise.

If it ain't broke, I can fix that.
Sandman!
Honored Contributor

Re: ipcs in awk-script

Inesa,

Yet another way to do this would be:

# ipcs -smo | grep | awk '{system("ipcrm -"$1" "$2)}'

regards!
Muthukumar_5
Honored Contributor

Re: ipcs in awk-script

Use like this:

ipcs -smo | awk '/^m|^s/ { print "ipcrm -"$1" "$2 }' | ksh

or

ipcs -smo | awk '/^m|^s/ { system ( "ipcrm -"$1" "$2); }'

hth.
Easy to suggest when don't know about the problem!