42

I'm unable to kill a process using any of the techniques I'm aware of ("Force Quit" in Activity Monitor, top, killall from the Terminal) and wonder if there are some additional steps I can take.

enter image description here

~ $ sudo killall -KILL 77439
Password:
No matching processes were found
~ $ killall -KILL 77439
No matching processes belonging to you were found
~ $ killall 77439
No matching processes belonging to you were found
~ $ killall Mathematica
No matching processes belonging to you were found

FWIW the process is "Mathematica" which I cannot relaunch, Quit, or Force Quit, or sample, either by name or PID, and it appears to have some odd side effects (screenshots don't appear, can't empty trash, and can't even shut down the system).

Are there additional steps that can be taken to really really kill a badly behaved process?

orome
  • 11,983
  • 64
  • 144
  • 260
  • Can you find this process using top in the terminal? – Pierobon Feb 01 '14 at 19:03
  • 1
    Next time this problem does occur, please add the output of ps alx | egrep '[ /](PID|Math)' to your question. – dan Feb 01 '14 at 20:25
  • @danielAzuelos: Good tip. Will do. – orome Feb 01 '14 at 20:31
  • GDP2 links(below) to interesting stuff on sending a kill signal to a kernel thread. It's about GNU/Linux. But what's been gnawing at me, and this question kind of asks it: I recall (perhaps in Pre OS X days?) that there were serious keyboard commands that might grab the attention of an errant program, similar to Ctrl-C, Ctrl-D and Ctrl-Z in a shell. Command-.(period)?? Anything like that relevant today? Any ways to tell what kill signals a process/app will respond to? Any useful signals to send to any common macOS apps other than STOP, CONT, ILL, KILL, which I've found useful. Or ... – WHO'sNoToOldRx4Covid-CENSORED Nov 15 '21 at 08:43
  • ...or has anyone found attaching a debugger or reviewing a core dump to be useful? Perhaps these are more of a developer.apple.com/forums questions? For example, I have an iPad app on my Mac that has hung. I entered a long comment - I just realized I can take a screen shot and Photos will give me the text back. But what if I've entered a long comment and the app has frozen and most of the comment is invisible. But the app is alive enough to refresh the window... Who's been there? – WHO'sNoToOldRx4Covid-CENSORED Nov 15 '21 at 08:48

4 Answers4

61

killall kills by process name (which is definitively not 77439 and most probably also not Mathematica). You can use kill 77439 or (if this fails) kill -9 77439 instead (but if the process is really stuck, only a reboot will solve the problem).

Also, due the the way sending/processing of signals (like kill -9) works in Unix/OS X, there are situations where a process will be unkillable. One typical example for this is if a process gets stuck while accessing some external device and never actually gets control back. In such situations a reboot is the only way to get rid of the process.

nohillside
  • 100,768
  • 3
    Kill sounds like it should go just as it says, but really it should be called 'send interrupt signal', as there are many different types of kill it can perform. Using the parameters -9 essentially uses the most powerful form of terminating with extreme predjudice available... – stuffe Feb 01 '14 at 18:14
  • 2
    $kill -9 PID always does the trick for me, even if it's that much invasive. – Pierobon Feb 01 '14 at 19:05
  • So it seems like Mathematica is just unusually badly behaved. In the end I had to force shutdown (regular shutdown hung). I don't have this problem with any other app, but Mathematica has had it more than once. – orome Feb 01 '14 at 19:09
  • 2
    Here are some more details about what can cause processes to get stuck. – GDP2 Jan 09 '18 at 20:41
  • I'll second kill -9. The only time I have had a "sudo kill -9" fail was on a system that was completely borked and needed rebooted anyway. – MikeP Sep 07 '18 at 19:55
  • How on earth does the OS not have the final say on killing an App in user-space? So an app can just, ignore the request? – Tom Nov 19 '21 at 16:19
  • @Tom See the second paragraph of the answer. The way Unix works, a process must be running to handle any signal sent to it (which it can't if it is waiting for an external device or stuck in some kernel routine). And terminating processes which are stuck in kernel space may have unexpected side-effects. But apparently there is a way now, see https://apple.stackexchange.com/a/390819/9058 – nohillside Nov 19 '21 at 16:23
  • @nohilside, I was actually responding to the second paragraph. Not to start a chat, I just found it fascinating that the OS isn't sandboxed enough to close an app without fear of side-effects in kernel. – Tom Nov 19 '21 at 16:26
  • 1
    @Tom That part of of how Unix works is probably nearly as old as the OS itself. Most probably things would be designed differently today (OTOH it's a rare issue). – nohillside Nov 19 '21 at 16:28
  • @orome May I ask whether you've found a correlation with any specific thing you do with Mathematica? I use Mathematica a lot (fortunately, it's never happened to me with it; it happened to me with Opera today, which was a problem for a while). – Rain Jun 18 '23 at 21:30
5

Sometimes killing the parental process can get rid of an otherwise unkillable process. Unfortunately, if the parental process is PID 0 or 1 (launchd) you are pretty screwed.

Find the parental process in Activity Monitor.

d-b
  • 3,348
  • 6
  • 38
  • 62
3

On newer os, use launchctl to trigger a reboot of the apps / user space.

launchctl reboot apps
launchctl reboot logout
sudo launchctl reboot userspace

I would start with apps after saving your work, then progress to a logout and then the userspace reboot. You shouldn’t need to restart the entire OS unless things are really broken far past one stuck process. Stop as soon as the first one of the above commands gives you relief.

You may find an iPad or iPhone or another computer to ssh in makes it easier to quit things since if you run terminal app, it will exit after the first command.

bmike
  • 235,889
  • I tried this, and after the first launchctl command ran, my terminal app immediately exited, lol. I couldn't run the other two commands. – coredumperror Aug 09 '21 at 17:13
  • 1
    Thank you so much, @coredumperror . I have been using ssh for so long I forget to explain that. Is my edit more useful for you than the older version of this answer? – bmike Aug 09 '21 at 22:48
  • Well, the third of those worked for me. I was having the same problem as OP with Opera on macOS 13.4. Tried sudo kill -9 and d-b's solution, neither of which worked (the parent process ID was 1), then tried your first two commands, also to no avail. The third one thankfully worked. Thank you! – Rain Jun 18 '23 at 21:24
  • Worked for me, thanks. – Nick Bolton Dec 24 '23 at 01:46
-4

Running macOS Mojave 10.14 Beta 1, I had to run the following to get any traction:

sudo xcscontrol --reset   
  • 4
    What exactly does this do / why is it needed? – pkamb Nov 01 '18 at 22:06
  • xcscontrol is Xcode Server Control, and doesn't seem to have any correlation to a badly behaved process? – Matt Sephton Mar 13 '19 at 16:36
  • I've got this on running the command: Failed: Current Xcode symlink (/Library/Developer/XcodeServer/CurrentXcodeSymlink) not found, service doesn't appear to be configured. – Vladyn Jul 27 '20 at 04:02