close

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

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to kill process on GPUs with PID in nvidia-smi using keyword in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

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

  1. 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.

  2. 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.

Method 1

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.

Method 2

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’)

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read