Created
March 13, 2017 06:43
-
-
Save WeiTang114/bfaebde2be827c73d15e936e19383622 to your computer and use it in GitHub Desktop.
Show username after each process in nvidia-smi.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. This is working perfectly.