lucius
lucius

Reputation: 2427

How to kill a process in 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

Upvotes: 128

Views: 315878

Answers (12)

Mateus Alves de Oliveira
Mateus Alves de Oliveira

Reputation: 1031

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 the process running on the port will be listed. Then you just have to kill the found Process ID like this:

kill -9 PID_NUMBER

Where PID_NUMBER is the Process ID running on the port.

And -9 is the option KILL (non-catchable, non-ignorable kill)

Upvotes: 11

Rakesh Bakoriya
Rakesh Bakoriya

Reputation: 181

You can access the Force Quit dialogue box by pressing + + esc, or using the Apple Menu (top left corner of the screen) and choosing Force Quit... Select the problem app, and click the Force Quit button.

enter image description here

Upvotes: 2

mh taqia
mh taqia

Reputation: 3596

To terminate a process:

kill -s KILL [PID]

Where -s specifying the signal name to be sent to PID

Upvotes: 0

Garrett
Garrett

Reputation: 8080

If you know the process name you can use:

killall Dock

(Replacing "Dock" with the process name.) If you don't know the name of the process, you can open Activity Monitor and find it.

Upvotes: 9

prashant.kr.mod
prashant.kr.mod

Reputation: 1712

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

enter image description here

Upvotes: 2

monish_koppa
monish_koppa

Reputation: 341

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.

Upvotes: 0

Gajen Sunthara
Gajen Sunthara

Reputation: 4816

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

Upvotes: 30

ArcaneVibe
ArcaneVibe

Reputation: 67

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!

Upvotes: 4

Charlie Martin
Charlie Martin

Reputation: 112404

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.

Upvotes: 193

koan
koan

Reputation: 3686

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.

Upvotes: 2

Rob Napier
Rob Napier

Reputation: 299545

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.

Upvotes: 3

Alex Martelli
Alex Martelli

Reputation: 882401

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:-(.

Upvotes: 4

Related Questions