Search code examples
pythongpunvidiakeywordpid

How to kill process on GPUs with PID in nvidia-smi using keyword?


How to kill running processes on GPUs for a specific program (e.g. python) in terminal? For example two processes are running with python in the top picture and kill them to see the bottom picture in nvidia-smi

For example two processes are running with python in the top picture and kill them to see the bottom picture in nvidia-smi


Solution

  • You can grep "python" in the nvidia-smi and then pass the PID to the kill -9 command, e.g.

    sudo kill -9 $( nvidia-smi | grep 'python' | sed -n 's/|\s*[0-9]*\s*\([0-9]*\)\s*.*/\1/p' |  sed '/^$/d')