Created
January 5, 2017 01:50
-
-
Save jorben/3f1524ee12646d384ecbf121b3fc6077 to your computer and use it in GitHub Desktop.
有时候看到某个shm有好几个进程attach了,但是具体是哪些进程呢? 网上查了一下,http://stackoverflow.com/questions/5658568/how-to-list-processes-attached-to-a-shared-memory-segment-in-linux 方法是grep $shmid /proc/*/maps 可以找出attach的进程。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -lt 1 ]; then | |
echo "usage: " $0 " shmid ..." | |
exit 0 | |
fi | |
tmpfile=/tmp/shm$$ | |
for x ; do | |
grep $x /proc/*/maps > $tmpfile 2>/dev/null | |
echo ==== $x ==== | |
pids=$(awk -F/ '{print $3}' $tmpfile) | |
for pid in $pids; do | |
echo $pid $(cat /proc/$pid/cmdline | tr '\000' ' ') | |
done | |
done | |
rm $tmpfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment