How to kill running processes by name from the terminal - shell

I want to kill all processes named ruby. How do I do that in one go, without manually doing kill -9 PID for every process?

A simple oneliner should do the trick for you:
ps aux | grep [s]lack | awk '{print $2}' | xargs kill -9
ps aux -> list all processes
grep -> search for a particular process by name or any identifier
awk '{print $2}' -> get the 2nd column entries from the result of grep
xargs kill -9 -> kill the processes.

killall command may solve your problem. Please check the manual for details.

Related

How to use xargs to pass arguments as sudo to given program in terminal shell

I want kill a series process like follow:(rg is a grep alternative)
ps -aux | rg "some_procs" | awk '{print $2}' | xargs kill -9
but It raise an error message show I don't have permission. I also can't add sudo neither after xargs or behind xargs.(seems it will cause xargs assign argus to sudo rather kill).
How do I use sudo in this pipe link to kill those processes?
ps -aux | rg "mytmp" | awk '{print $2}' | xargs sudo kill -9
this command worked.
In addition to
the answer,
if you are using GNU/Linux box, you could have use
pkill so
sudo pkill some_procs
Also note that, otherwise, your can pass many PIDs to kill OK. You don't need all ps default fields, but only PID and name to filter. Last, you can skip the rg part because you can do it in awk directly.
sudo kill -9 $(ps -o pid,args | awk '$2 ~ /some_procs/ {$1}')

How to get and kill the process Mac terminal

Find specific client with name and memory
Get the client pId
Kill pId
Can I do kill that process just within the terminal.
What I tried
ps aux | grep leagueClientUxHelper | awk '{print $2}'
but I can't get the large memory process.
Same process names in activated status:
You can kill a process with the id by using the kill command.
ps aux | grep TextEdit | awk '{print $2}' | xargs kill
That will pipe it directly into the kill command. You will get an error because the ps aux will show two PIDs but it won't cause any problems.
Kill only works with PIDs
Are you trying to drill down to a certain memory length or compared to another instance like league1 memory is > leage2 memory?

Killing a running sh script using pid

I have made an Auto Clicker and was wondering how i would kill it using
kill [pid]
My auto Clicker works like this:
while true [1]; do
xdotool click --repeat 10000 --delay 150 1
done
code I have used to try and terminate running proccess:
ps -ef | grep AutoClicker | grep -v grep | xargs kill -9
I found this code on another post, however i have had no luck with it.
pkill -f AutoClicker or kill $(pgrep -f AutoClicker)
If you run your code:
ps -ef | grep AutoClicker | grep -v grep | xargs kill -9
you should get an error message from kill.
kill expects a list of process ids not usernames, times, and random strings.
You need to filter out everything except the pids with something like:
ps -ef | grep AutoClicker | grep -v grep | awk '{print $2}' | xargs kill
Instead of searching for the process ID, use your own "PID file". I'll demonstrate with sleep in place of xdotool.
echo $$ > /tmp/my.pid
while true [1]; do
echo "clicking"
sleep 5
done
# rm -f /tmp/my.pid
I can run this script in another terminal window or the background. The important thing is that /tmp/my.pid contains the process ID of this running script. You can stop it with:
kill $(</tmp/my.pid)
This interrupts the while-loop. Need to figure out how to remove the PID file...

How do I make a stop after a run?

If I do a:
npm run script
Can I stop it with a stop?
npm stop script
Why I tried it and it does not work.
I know that with the combination of "Ctrl + c" I kill it, but I want to do it by command.
Try something like that:
ps -ef | grep script | awk '{print $2}' | head -n1 | xargs kill -9
This command should find first process named script on the list of all unix processes created by all users and kill it by with using its PID.

ps aux auto close app

I'm trying to setup a task to kill certain server processes when the server gets into a weird state such as when it fails to boot one process, but another process gets keeps running and so not everything boots up. This is mainly a task for development so you can do jake killall to kill all processes associated with this project.
I'm having trouble figuring out how to get the pid after doing: ps aux | grep [p]rocess\ name | {HOW DO I GET THE PID NOW?} and then after getting the ID how do I pass that to kill -9 {PID HERE}
The PID is the second column, so you can do
ps aux | grep [p]rocess\ name | awk '{print $2}'
All together,
my_pid=$(ps aux | grep [p]rocess\ name | awk '{print $2}')
kill -9 $my_pid
You could also you killall <program> or pkill <program> or pgrep <program>

Resources