By Dan Moren
July 30, 2015 11:48 AM PT
Tip: Force-quitting a runaway Mac process remotely
Note: This story has not been updated for several years.
We’ve all probably encountered a problem like this: you’ve gotten up to get a snack or take care of something around the house (or office), returned to your desk and realized that your Mac is behaving oddly–frozen, perhaps, or simply very sluggish. Too often that means shutting down the whole computer, but that can be disruptive or, if you have unsaved data, worse. Depending on exactly what has your Mac locked up, however, there could be another way.
Yes, it’s our old friend Terminal. In order for this tip to work you’ll need to have previously enabled Remote Login in the Sharing preference pane. You’ll also need to have another Mac handy, or an iOS device with an SSH app; I recommend Panic’s excellent Prompt.
First things first: open up Terminal on OS X or your SSH client on iOS and connect to the troublesome Mac. From the command line, you can enter this:
Username is your OS X account’s “short name” (the name of your home directory) and computer is your computer’s name, as specified under the Sharing pane. So, for example, if my username were
dan on my computer
Athas, I’d write:
When prompted, enter your password1–depending on just how locked up your Mac is, this might take a while. (In some cases restarting is faster, but if you’ve got unsaved work, this method may still be preferable.)
Eventually a command line for the remote computer should appear (usually prefixed with the name of the computer) and the current directory. In the previous example, I should see something like this:
As the movie hackers say: “we’re in.”
Okay, now to figure out what’s got your computer grinding away. As you probably know, the probable culprits include a program using excessive CPU or one that’s eating up too much memory. If you were sitting at your computer, you could pull up Activity Monitor and look–of course, if you could do that, you wouldn’t need to resort to this whole rigmarole.2
Fortunately, Activity Monitor has a command-line analog:
top shows you a live, updating table of the processes running on your computer, along with some overall stats on memory consumption, CPU usage, and so on. Here’s an example:
Most of that probably looks like gibberish, but don’t worry too much: with a little extra garnish,
top can also help us pick out our offending apps.
-o switch lets you specify what to sort the processes by. If you want to sort by CPU usage, for example, you’d issue this command:
top -o CPU
Memory usage, however, is a little trickier. Sorting by
MEM might seem the obvious choice, but that actually only accounts for physical memory. These days, modern OSes rely almost as much on intelligent usage of virtual memory as they do physical.
If you don’t see any obvious culprits using
MEM then consider instead sorting by
vsize, which might help give you another angle on the problem.3 (To re-sort the columns, you need to quit
top which you can do by simply hitting the
Should you spot a process that seems like it’s misbehaving, you’ll want to make note of the number in the PID (“process ID”) column. Then quit the app and issue the following command, substituting the number for PID, to try and off the offending program:
sudo kill -9 PID
The account you’ve logged into should be an administrator in order to do this, since you’ll need to enter your account password.
If all goes well, this should kill the problematic process and return your system to a more usable state in short order. You can leave the remote session by quitting Terminal or your SSH app, or simply issuing a
Of course, there’s no guarantee that any of this will work–in the end, force-rebooting your Mac may be the only real solution. But if you’re concerned about not losing work, it might be worth your time to give this a shot.
- If you’ve never before used SSH to access your computer, you may be prompted to accept the “fingerprint” of that computer–essentially confirming that machine is the one you believe it to be so that an encrypted connection can be established. ↩
You can, however, force the remote computer to try and launch Activity Monitor by entering
open /Applications/Utilities/Activity Monitor.app, but depending on the state of the machine, that may take a very long time. ↩
- In particular, Safari–often a memory hog–is divided up into many separate processes which seem to make extensive (and sometimes excessive) use of virtual memory. ↩
[Dan Moren is the East Coast Bureau Chief of Six Colors. You can find him on Twitter at @dmoren or reach him by email at firstname.lastname@example.org. The latest novel in his Galactic Cold War series of sci-fi space adventures, The Nova Incident, is available now.]
If you appreciate articles like this one, support us by becoming a Six Colors subscriber. Subscribers get access to an exclusive podcast, members-only stories, and a special community.