Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill a process in MacOS?

Tags:

macos

I tried kill -9 698 but the process did not die.

$ ps -ef | grep chromium   502   698   811   0   0:01.24 ??         0:07.28 /Users/lucius/chromium/src/xcodebuild/Debug/Chromium.app/Contents/MacOS/Chromium   502   854   732   0   0:00.00 ttys001    0:00.00 grep chromium $ kill -9 698   $ ps -ef | grep chromium   502   698   811   0   0:01.24 ??         0:07.28 /Users/lucius/chromium/src/xcodebuild/Debug/Chromium.app/Contents/MacOS/Chromium   502   854   732   0   0:00.00 ttys001    0:00.00 grep chromium 
like image 513
lucius Avatar asked May 24 '09 04:05

lucius


People also ask

How do I find and kill a process on a Mac?

Press Command-Option-Esc to display the Force Quit menu, choose the application, and press Force Quit. If the Finder is not working, click on the Apple menu, choose Force Quit, select the application, and press Force Quit. Launch Terminal and follow the steps for killing a process above.


2 Answers

If you're trying to kill -9 it, you have the correct PID, and nothing happens, then you don't have permissions to kill the process.

Solution:

$ sudo kill -9 PID 

Okay, sure enough Mac OS/X does give an error message for this case:

$ kill -9 196 -bash: kill: (196) - Operation not permitted 

So, if you're not getting an error message, you somehow aren't getting the right PID.

like image 152
Charlie Martin Avatar answered Oct 11 '22 14:10

Charlie Martin


Some cases you might want to kill all the process running in a specific port. For example, if I am running a node app on 3000 port and I want to kill that and start a new one; then I found this command useful.

Find the process IDs running on TCP port 3000 and kill it

kill -9 `lsof -i TCP:3000 | awk '/LISTEN/{print $2}'` 
like image 24
Gajen Sunthara Avatar answered Oct 11 '22 14:10

Gajen Sunthara