Skip to content

Instantly share code, notes, and snippets.

@yunho-c
Created April 9, 2025 22:49
Show Gist options
  • Save yunho-c/aa4448abe09520de5e3cdf0d47d77113 to your computer and use it in GitHub Desktop.
Save yunho-c/aa4448abe09520de5e3cdf0d47d77113 to your computer and use it in GitHub Desktop.
nvidia_vram_usage_by_user.sh
#!/bin/bash
# Shows which processes & users are consuming GPU memory for Nvidia GPUs.
echo "User, PID, Used Memory, GPU ID"
# Get the GPU processes information
nvidia-smi --query-compute-apps=pid,used_memory,gpu_bus_id --format=csv,noheader | while read line
do
# Extract PID from the line - use cut instead of awk for CSV format
pid=$(echo $line | cut -d',' -f1 | tr -d ' ')
# Get username for the process
username=$(ps -o user= -p $pid 2>/dev/null)
# Check if we got a username and the process exists
if [ ! -z "$username" ]; then
echo "$username, $line"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment