Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to find out the processes attached to a shared memory?

905 views
Skip to first unread message

Ken

unread,
Jan 29, 2008, 5:58:59 AM1/29/08
to
On a typical database system, there are hundreds processed that
attached to a shared memory. How to find out the process id of these
processes?

T ID KEY MODE OWNER GROUP NATTCH
Shared Memory:
m 768 0xe42805c --rw-rw---- oracle dba 1793

Michael Tosch

unread,
Jan 29, 2008, 10:46:05 AM1/29/08
to

ipcs -mcp

man ipcs

Here is an old script for demonstration:


#!/bin/sh
# This is to clean up ipc shared memory
# It is not fully tested - perhaps can break a running application
#
#
PATH=/bin:/usr/bin:/usr/sbin:/usr/ucb
export PATH
# ipcs format is platform dependent:
uname -s | grep SunOS >/dev/null || exec echo "wrong platform"
#
echo "freeing unused shared memory segments left from applications"
#
ipcs -mcp |
while read t id key mode owner group creator cgroup cpid lpid
do
case "$t $id" in
m\ [1-9]*)
ps -ef | awk '
$1~/^('"$owner"'|'"$creator"')$/&&($2~/^('"$cpid"'|'"$lpid"')$/||$3~/^('"$cpid"'|'"$lpid"')$/)' |
grep . && continue
echo ipcrm -m "$id"
# ipcrm -m "$id"
sleep 1
;;
esac
done
#

(For real execution, remove the # before the ipcrm)

--
Michael Tosch @ hp : com

Ken

unread,
Jan 29, 2008, 9:48:14 PM1/29/08
to
Thank you replying. The script you provided can clean up the shared
mem that no processes is attached.
But my question is different: How to find out the process id that ARE
still attached to a share mem segment?

There is another way to cleanup the shared mem: find out those
NATTCH=0 and remove them
for example:
#ipcs -mo
IPC status from <running system> as of Tue Jan 29 19:41:11 GMT 2008


T ID KEY MODE OWNER GROUP NATTCH
Shared Memory:

m 2552582 0x2355 --rw------- root staff 0
m 2034965 0x715f --rw------- root staff 0
m 3038502 0x749a --rw------- root staff 0

for ID in ` ipcs -mo | awk '{if ($7==0) print $2}'` do
ipcrm -m $ID
done

0 new messages