终止所有使用 GPU 的 Python 进程

终止所有使用 GPU 的 Python 进程

我有以下情况,但我不想逐个输入使用任一 GPU 的每个 Python 进程的 PID。我该怎么做?

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1831      C   python3.8                         137MiB |
|    0   N/A  N/A      2266      C   python3.8                         137MiB |
|    0   N/A  N/A      2612      C   python3.8                         137MiB |
|    0   N/A  N/A      2722      G   /usr/bin/X                          9MiB |
|    0   N/A  N/A      2758      C   python3.8                         137MiB |
|    0   N/A  N/A      2971      G   /usr/bin/gnome-shell                6MiB |
|    0   N/A  N/A     20403      C   python3.8                         137MiB |
|    0   N/A  N/A     21616      C   python3.8                         137MiB |
|    1   N/A  N/A      1831      C   python3.8                         137MiB |
|    1   N/A  N/A      2266      C   python3.8                         137MiB |
|    1   N/A  N/A      2612      C   python3.8                         137MiB |
|    1   N/A  N/A      2758      C   python3.8                         137MiB |
|    1   N/A  N/A     20403      C   python3.8                         137MiB |
|    1   N/A  N/A     21616      C   python3.8                         137MiB |
+-----------------------------------------------------------------------------+

更新:我使用了killallkillall python3.8但都不起作用:

[jalal@goku ~]$ nvidia-smi
Thu Jun 10 19:29:19 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.67       Driver Version: 460.67       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 108...  Off  | 00000000:05:00.0 Off |                  N/A |
|  0%   35C    P2    59W / 250W |    843MiB / 11178MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX 108...  Off  | 00000000:06:00.0 Off |                  N/A |
|  0%   37C    P2    61W / 250W |    826MiB / 11178MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1831      C   python3.8                         137MiB |
|    0   N/A  N/A      2266      C   python3.8                         137MiB |
|    0   N/A  N/A      2612      C   python3.8                         137MiB |
|    0   N/A  N/A      2722      G   /usr/bin/X                          9MiB |
|    0   N/A  N/A      2758      C   python3.8                         137MiB |
|    0   N/A  N/A      2971      G   /usr/bin/gnome-shell                6MiB |
|    0   N/A  N/A     20403      C   python3.8                         137MiB |
|    0   N/A  N/A     21616      C   python3.8                         137MiB |
|    1   N/A  N/A      1831      C   python3.8                         137MiB |
|    1   N/A  N/A      2266      C   python3.8                         137MiB |
|    1   N/A  N/A      2612      C   python3.8                         137MiB |
|    1   N/A  N/A      2758      C   python3.8                         137MiB |
|    1   N/A  N/A     20403      C   python3.8                         137MiB |
|    1   N/A  N/A     21616      C   python3.8                         137MiB |
+-----------------------------------------------------------------------------+
[jalal@goku ~]$ killall python3.8
[jalal@goku ~]$ nvidia-smi
Thu Jun 10 19:29:26 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.67       Driver Version: 460.67       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 108...  Off  | 00000000:05:00.0 Off |                  N/A |
|  0%   35C    P2    59W / 250W |    843MiB / 11178MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX 108...  Off  | 00000000:06:00.0 Off |                  N/A |
|  0%   37C    P2    62W / 250W |    826MiB / 11178MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1831      C   python3.8                         137MiB |
|    0   N/A  N/A      2266      C   python3.8                         137MiB |
|    0   N/A  N/A      2612      C   python3.8                         137MiB |
|    0   N/A  N/A      2722      G   /usr/bin/X                          9MiB |
|    0   N/A  N/A      2758      C   python3.8                         137MiB |
|    0   N/A  N/A      2971      G   /usr/bin/gnome-shell                6MiB |
|    0   N/A  N/A     20403      C   python3.8                         137MiB |
|    0   N/A  N/A     21616      C   python3.8                         137MiB |
|    1   N/A  N/A      1831      C   python3.8                         137MiB |
|    1   N/A  N/A      2266      C   python3.8                         137MiB |
|    1   N/A  N/A      2612      C   python3.8                         137MiB |
|    1   N/A  N/A      2758      C   python3.8                         137MiB |
|    1   N/A  N/A     20403      C   python3.8                         137MiB |
|    1   N/A  N/A     21616      C   python3.8                         137MiB |
+-----------------------------------------------------------------------------+
[jalal@goku ~]$ killall
Usage: killall [-Z CONTEXT] [-u USER] [ -eIgiqrvw ] [ -SIGNAL ] NAME...
       killall -l, --list
       killall -V, --version

  -e,--exact          require exact match for very long names
  -I,--ignore-case    case insensitive process name match
  -g,--process-group  kill process group instead of process
  -y,--younger-than   kill processes younger than TIME
  -o,--older-than     kill processes older than TIME
  -i,--interactive    ask for confirmation before killing
  -l,--list           list all known signal names
  -q,--quiet          don't print complaints
  -r,--regexp         interpret NAME as an extended regular expression
  -s,--signal SIGNAL  send this signal instead of SIGTERM
  -u,--user USER      kill only process(es) running as USER
  -v,--verbose        report if the signal was successfully sent
  -V,--version        display version information
  -w,--wait           wait for processes to die
  -Z,--context REGEXP kill only process(es) having context
                      (must precede other arguments)

答案1

$ killall -9 python3.8

这里,SIGKILL(9)将强制它退出。

致谢VG9t

相关内容