Shell command for killing all the processes together, that we found using grep command

Sometime when we found a lot of process associates with a software or something that may hurt our memory or CPU, and it would be nice to kill that all process and be our system in a fine position. But when there is so many process we can’t kill all the process by hand using the command

 $ kill -9 PID

where ‘PID’ is the process id.

Shell commands will help us to do this. See below

First you create a .sh file file named ‘killAllProcess.sh’.

#!/bin/bash
echo "Usage : ./killAllProcess.sh "
for i in `ps ax | grep $1 | grep -v grep | sed 's/ *//' | sed 's/[^0-9].*//'`
do
  kill -9 $i
done
echo "Killed All the process which has name with $1"

And make this file executable

$ chmod +x killAllProcess.sh 

Then run it

 $ ./killAllProcess.sh 

And see any process with that name is there

$ ps aux | grep PROCESS_NAME

All vanishes..!!

Advertisement

Author: Abhilash

I'm Abhilash, a web developer who specializes in Ruby development. With years of experience working with various frameworks like Rails, Angular, Sinatra, Laravel, NodeJS, React and more, I am passionate about building robust and scalable web applications. Since 2010, I have been honing my skills and expertise in the Ruby on Rails platform. This blog is dedicated to sharing my knowledge and experience on topics related to Ruby, Ruby on Rails, and other subjects that I have worked with throughout my career. Join me on this journey to explore the exciting world of web development!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: