Skip to content

Instantly share code, notes, and snippets.

@iamgroot42
Last active February 12, 2017 08:42
Show Gist options
  • Save iamgroot42/7abd7e5bf9dd625aa090b29bfe3c4474 to your computer and use it in GitHub Desktop.
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)
#!/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