How can I kill a process by its name?
Sometimes I notice that the process Python
hung up. Then I'll kill it via the Activity Monitor and everything is fine.
I'd like to kill that process in the Terminal instead. However, looking up the PID
seems kind of unecessary because there's only one process by the name Python
.
Is it possible to kill a process by its unique name?
You should be able to run the command sudo killall Python
.
You need to run as root because Python belongs to root, not the user.
sudo killall -s SIGINT "process name"
If you can't be a sudo because it will ask for password and I feel you don't want that in a script. pkill come for rescue :)
pkill -9 "process name"
You can kill Applications by using Activity Monitor.app, being the GUI solution. That would be a simple "force quit". However, that doesn't always work out for different reasons in some situations!
The command-line solution as mentioned in the comment above holds a lot more options for the user. sudo killall Python
or if it is a running program-process sudo killall /Applications/Whatever.app
forces the the process to quit as well.
You can also force a process to quit, using its assigned PID. In the case of Activity Monitor.app it would be kill 25794
or kill -9 25794
Some more details:
The kill program in Terminal simply force quits a program, as though by remote control. (It even works when you SSH into your Mac from a remote location. Follow the kill command with the process ID number (short PID) of the program you want to terminate.
Unless you also use sudo, you can kill only programs you “own”—those running under your account. (The operating system itself—root—is always running programs of its own, and it’s technically possible that other people, dialing in from the road, are running programs of their own even while you’re using the Mac!)
The -9
flag is a “non-catchable, non-ignorable kill.” In other words, it’s an industrial-strength assassin that accepts no pleas for mercy from the program you’re killing.