Last active
February 12, 2017 08:42
-
-
Save iamgroot42/7abd7e5bf9dd625aa090b29bfe3c4474 to your computer and use it in GitHub Desktop.
A simple script to keep track of which user has used a GPU for how much time (for a single GPU machine)
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 | |
pids=$(nvidia-smi | awk '$2=="Processes:" {p=1} p && $3 > 0 {print $3}' | grep -o '[0-9]*') | |
if [ ${#pids[@]} -gt 0 ] | |
then | |
date >> GPU_LOGFILE | |
fi | |
for p in $pids | |
do | |
u=$(ps -u -p $p | awk '{print $1}' | tail -1) | |
m=$(ps -u -p $p | awk '{print $10}' | tail -1) | |
echo "$u $m" >> GPU_LOGFILE | |
done | |
echo '' >> GPU_LOGFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment