Sometimes we only know the PID (e.g. from nvidia-smi). We do not know what container the PID is running in.
|
1 2 3 4 5 6 7 8 9 |
TARGET_PID=331711 for container in $(docker ps -q); do if docker top $container | awk '{print $2}' | grep -q $TARGET_PID; then container_name=$(docker inspect --format '{{.Name}}' $container | sed 's/^\/\(.*\)/\1/') echo "PID $TARGET_PID is running in container: $container (Name: $container_name)" exit 0 fi done echo "PID $TARGET_PID is not running in any active container." |
