DEV Community

Discussion on: Killing many procs at one time

Collapse
ikirker profile image
Ian Kirker

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.