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

salehinejad picture salehinejad · May 5, 2018 · Viewed 26.3k times · Source

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

Answer

Ainz Titor picture Ainz Titor · May 4, 2019

The accepted answer doesn't work for me, probably because nvidia-smi has different formats across different versions/hardware.

I'm using a much cleaner command:

nvidia-smi | grep 'python' | awk '{ print $3 }' | xargs -n1 kill -9

You can replace $3 in the awk expression to fit your nvidia-smi output. It is the n-th column in which the PIDs occur.