Sometimes I have a desire to kill many processes using just one line of my BASH console. All this stuff like finding out PIDs from top or ps comman...
For further actions, you may consider blocking this person and/or reporting abuse
How does what you're doing, above, differentiate from just using
pkill
and related tools?That's a good question and the answer would be
nothing
, sopkill
does that out from the box and you could easily use it instead!Honestly I just tried first solution off the top of my head, so that works fine for me, but thanks for the good advice anyway ¯_(ツ)_/¯
Ok. Cool. I used to do similar (back in my Solaris days before Sun finally got around to adding the ps-tools to their OS). Looked similar to that, but I wanted to make sure I wasn't missing something. =)
No, you mayn't have to worry, they are the same things!
So, a few things.
killall is already a command that is widely installed and very commonly used. It serves exactly this purpose. Two commands, even, if you consider the older SystemV and Solaris program called killall that just kills all processes and takes no arguments.
This approach is extremely unsafe because you haven’t bounded your grep expression or put any other conditions on it: if you have a program whose name is a number, whose name is part of a user’s username, or whose name is a substring of another program’s name (e.g. ssh and sshd), these will all get caught in your grep search, so many processes could get killed inadvertently.
This approach is incredibly unsafe because if you run it with no arguments you will kill every process except grep processes, which will do bad things to your OS.
Process IDs aren’t always 6 digits or fewer: while a 32-bit Linux machine may have up to 32768 processes, 64-bit Linux expands that potential range beyond 6 digits. This means your cut expression may truncate the PID of the actual process you’re looking for.
I would add something like:
Yeah, thanks for the another good advice!
You know checking whether the name exists is a good way not to have any issues with tools like
kill
.It's funny that the example you chose is Slack :D I heard it can become quite a memory hog!
Thanks for the tip!
Honestly I just wanted to check whether it's closed, because
Slack
has an icon in the tray.Usually I am facing issues related to closing processes like
vpn connections
,third-party daemons
, because they don't have icons or GUI, so we can't be sure whether it's closed or not!The problem with daemons is that they are usually controller by the init system (upstart or systemd) generally. So once you kill it, the init system will respawn it. You will have to stop it from the init system