Skip to content

Instantly share code, notes, and snippets.

@WeiTang114
Created March 13, 2017 06:43
Show Gist options
  • Save WeiTang114/bfaebde2be827c73d15e936e19383622 to your computer and use it in GitHub Desktop.
Save WeiTang114/bfaebde2be827c73d15e936e19383622 to your computer and use it in GitHub Desktop.
Show username after each process in nvidia-smi.
#!/bin/bash
# Show username after each process in nvidia-smi
# like:
# ...
# +------------------------------------------------------+
# | Processes: GPU Memory |
# | GPU PID Type Process name Usage |
# |======================================================|
# | 0 150752 C python 830MiB | User: user1
# | 1 2185 C /usr/bin/python 1090MiB | User: user2
# ..
proc_lines=$(nvidia-smi | egrep "MiB \|$")
users=$(echo "$proc_lines" | awk '{print $3}' | xargs -n 1 ps -o user:20 --no-header -p)
awk 'BEGIN {s=-999} NR==FNR {u[NR]=$1; next}
{ if ($3=="GPU")
s = 0;
if (u[s-2])
{print $0 " User: " u[s-2]}
else
print $0; s=s+1
}' <(echo "$users") <(nvidia-smi)
@pourmand1376
Copy link

Thanks. This is working perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment