Skip to content

Instantly share code, notes, and snippets.

@jorben
Created January 5, 2017 01:50
Show Gist options
  • Save jorben/3f1524ee12646d384ecbf121b3fc6077 to your computer and use it in GitHub Desktop.
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的进程。
#!/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