【Linux】监视CPU、GPU使用情况

在运行大型程序时,需要关注计算机资源的占用情况,本文以ubuntu20.04为例,使用linux命令查看cpu和gpu的资源使用情况

一、CPU监视

1.1 top命令

使用系统自带的top命令

top

在这里插入图片描述

1.2 htop命令

htop工具可以更清晰地查看cpu资源使用情况

安装htop工具

sudo apt-get install htop

使用htop查看cpu使用情况

htop

在这里插入图片描述

二、GPU监视

2.1 显示当前GPU使用情况

Nvidia自带了一个nvidia-smi的命令行工具,会显示显存使用情况

nvidia-smi

在这里插入图片描述

2.2 2. 周期性输出GPU使用情况

使用watch命令:周期性执行某一命令,并将输出显示

用法:
 watch [options] command

选项:
  -b, --beep             如果命令以非零返回值退出的话则发出哔声
  -c, --color            interpret ANSI color and style sequences
  -d, --differences[=<permanent>]
                         highlight changes between updates
  -e, --errexit          exit if command has a non-zero exit
  -g, --chgexit          exit when output from command changes
  -n, --interval <secs>  seconds to wait between updates
  -p, --precise          尝试以精确的间隔运行命令
  -t, --no-title         关闭头部显示
  -x, --exec             将命令传给 exec 而非“sh -c”

 -h, --help     显示此帮助然后离开
 -v, --version  output version information and exit

设置为每 10s 显示一次显存的情况:

watch -n 10 nvidia-smi

在这里插入图片描述

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐