How to kill a process in MacOS?

Macos

Macos Problem Overview


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

Macos Solutions


Solution 1 - Macos

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.

Solution 2 - Macos

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}'`

Solution 3 - Macos

If you know the process name you can use:

killall Dock

If you don't you can open Activity Monitor and find it.

Solution 4 - Macos

I just now searched for this as I'm in a similar situation, and instead of kill -9 698 I tried sudo kill 428 where 428 was the pid of the process I'm trying to kill. It worked cleanly for me, in the absence of the hyphen '-' character. I hope it helps!

Solution 5 - Macos

If kill -9 isn't working, then neither will killall (or even killall -9 which would be more "intense"). Apparently the chromium process is stuck in a non-interruptible system call (i.e., in the kernel, not in userland) -- didn't think MacOSX had any of those left, but I guess there's always one more:-(. If that process has a controlling terminal you can probably background it and kill it while backgrounded; otherwise (or if the intense killing doesn't work even once the process is bakcgrounded) I'm out of ideas and I'm thinking you might have to reboot:-(.

Solution 6 - Macos

Given the path to your program, I assume you're currently running this under Xcode, and are probably at a debug breakpoint. Processes cannot be killed in this state because of the underlying implementation of breakpoints.

The first step would be to go to your Xcode process and stop debugging. If for some strange reason you have lost access to Xcode (perhaps Xcode has lost access to its gdb sub-process), then the solution is to kill the gdb process. More generally, the solution here is to kill the parent process. In your case this is PID 811 (the third column).

There is no need to use -9 in this case.

Solution 7 - Macos

I have experienced that if kill -9 PID doesn't work and you own the process, you can use kill -s kill PID which is kind of surprising as the man page says you can kill -signal_number PID.

Solution 8 - Macos

Do you can list the process using a port with command lsof, for example:

lsof -i tcp:PORT_NUMBER_HERE

Replace the word PORT_NUMBER_HERE to the port number that you are using, then a the process running on the port will be listed. Then you have just to kill the process ID founded like this:

kill PID_NUMBER

Where PID_NUMBER is the process ID running on the port.

Solution 9 - Macos

I recently faced similar issue where the atom editor will not close. Neither was responding. Kill / kill -9 / force exit from Activity Monitor - didn't work. Finally had to restart my mac to close the app.

Solution 10 - Macos

in the spotlight, search for Activity Monitor. You can force fully remove any application from here.

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionluciusView Question on Stackoverflow
Solution 1 - MacosCharlie MartinView Answer on Stackoverflow
Solution 2 - MacosGajen SuntharaView Answer on Stackoverflow
Solution 3 - MacosGarrettView Answer on Stackoverflow
Solution 4 - MacosArcaneVibeView Answer on Stackoverflow
Solution 5 - MacosAlex MartelliView Answer on Stackoverflow
Solution 6 - MacosRob NapierView Answer on Stackoverflow
Solution 7 - MacoskoanView Answer on Stackoverflow
Solution 8 - MacosMateus Alves de OliveiraView Answer on Stackoverflow
Solution 9 - Macosmonish_koppaView Answer on Stackoverflow
Solution 10 - Macosprashant.kr.modView Answer on Stackoverflow