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

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


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.


You can grep python in the nvidia-smi and then pass the PID tothe 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')


Use nvidia-smi or top command to see processes running and to kill command:

sudo kill -9 PID