I have many processes running by name gunicorn

ubuntu   23884  0.0  7.1 190092 71980 ?        S    Sep10   0:01 gunicorn: worker [ll1]
ubuntu   23885  0.0  6.8 187120 69128 ?        S    Sep10   0:01 gunicorn: worker [ll1]
ubuntu   23886  0.0  7.1 189800 71712 ?        S    Sep10   0:01 gunicorn: worker [ll1]

I want to kill all proccess by name gunicorn.Currently i am able to kill only one process by this script at a time.

pid=`ps ax | grep gunicorn | awk '{split($0,a," "); print a[1]}' | head -n 1`
echo $pid
kill $pid
echo "killed gunicorn"
pkill -f gunicorn
echo "killed gunicorn"

That will kill any process that has the name gunicorn on the line and print the killed gunicorn message.


You can use the kill all command and what signal you want to send:

killall -<signal> gunicorn

You can also use -v to output more information of what it is doing:

killall -v -<signal> gunicorn

Or to use a script like you are doing you could do something like this:


for pid in `pidof gunicorn`; do 
    kill -<signal> $pid;
    echo "killed gunicorn [$pid]"; 


enter image description here

  • Related: Why should I not use 'kill -9' / SIGKILL
    – Kusalananda
    Sep 11 '20 at 5:59
  • @Kusalananda, I did say kill all command and what signal you want to send. Or he can leave off the signal and I believe the default is sending a SIGTERM, but I believe when the operating system is closing down I think it sends out SIGTERM and waits and then sends out a SIGKILL. I will modify my answer and replace 9 with <signal>.
    – NiteRain
    Sep 11 '20 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.