Skip to content

Instantly share code, notes, and snippets.

@georg-wolflein
Created July 26, 2021 13:15
Show Gist options
  • Select an option

  • Save georg-wolflein/2df4393070e29c877fff79230600eee7 to your computer and use it in GitHub Desktop.

Select an option

Save georg-wolflein/2df4393070e29c877fff79230600eee7 to your computer and use it in GitHub Desktop.
Get the docker container ID containing a specified PID (useful to identify GPU-intensive processes when running nvidia-smi)
#/bin/bash
if [ -z "$1" ]
then
echo "Supply a PID as an argument!"
exit 1
fi
for i in $(docker ps -q)
do
OUTPUT=$(docker container top "$i" | grep "$1")
if [ $(docker container top "$i" | grep "$1" | wc -c) -ne 0 ]
then
docker ps -a | grep $i
exit 0
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment