Skip to content

Instantly share code, notes, and snippets.

@lonelyleaf
Last active June 18, 2020 02:26
Show Gist options
  • Save lonelyleaf/3581f9815b580c899d043dd023fd4afd to your computer and use it in GitHub Desktop.
Save lonelyleaf/3581f9815b580c899d043dd023fd4afd to your computer and use it in GitHub Desktop.
找到busy的mnt设备,不知道是哪里的祖传脚本……
#!/bin/bash
# A simple script to get information about mount points and pids and their
# mount namespaces.
if [ $# -ne 1 ];then
echo "Usage: $0 <devicemapper-device-id>"
exit 1
fi
ID=$1
MOUNTS=`find /proc/*/mounts | xargs grep $ID 2>/dev/null`
[ -z "$MOUNTS" ] && echo "No pids found" && exit 0
printf "PID\tNAME\t\tMNTNS\n"
echo "$MOUNTS" | while read LINE; do
PID=`echo $LINE | cut -d ":" -f1 | cut -d "/" -f3`
# Ignore self and thread-self
if [ "$PID" == "self" ] || [ "$PID" == "thread-self" ]; then
continue
fi
NAME=`ps -q $PID -o comm=`
MNTNS=`readlink /proc/$PID/ns/mnt`
printf "%s\t%s\t\t%s\n" "$PID" "$NAME" "$MNTNS"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment