ubuntu系统下查看是谁在使用GPU服务器
python 脚本
# -*- coding:utf-8 -*-
import os
def get_runing_gpu_pid():
re = []
fh = os.popen('nvidia-smi -q -d PIDS|grep Process\\ ID')
for pid in fh.readlines():
pid = pid.split(':')[1].strip('\r\n').replace(' ','')
re.append(pid)
return re
def find_user_by_pid(pid):
fh = os.popen('ps -aux|grep ' + str(pid))
for u in fh.readlines():
print u
if __name__=='__main__':
pids = get_runing_gpu_pid()
for pid in pids:
print(pid)
print(find_user_by_pid(pid))
shell脚本
#!/bin/bash
GPU_RUN_IDS=$(nvidia-smi -q -d PIDS | grep 'Process ID' | awk '{print $4}' | sort | uniq)
for gpu_run_id in GPU_RUN_IDS
do
echo $(gpu_run_id)
ps -aux| grep $(gpu_run_id) | grep -v grep
echo "===================================="
done
网友评论