Terminal 101: Track and Kill Processes

Every Monday, we'll show you how to do something new and simple with Apple's built-in command line application.

Every Monday, we'll show you how to do something new and simple with Apple's built-in command line application. You don't need any fancy software, or a knowledge of coding to do any of these. All you need is a keyboard to type 'em out!

Activity Monitor is one of OS X's many helpful built-in tools to help you figure out what applications are over-utilizing your Mac's processing power. It also gives you a glimpse into what applications are doing in the background and which ones are hogging up all of the resources. Today, we'll teach you how to do this in Terminal. And once you've mastered today's command, consider enabling SSH to remotely monitor your Mac's activity.

View Your Processes

Open Terminal, type in top, and press the enter key.You'll be presented with a real-time look at everything going on with your Mac's inner components. 

At the top of the window (show in red), you'll see how many applications are running, which are stuck in a "busy" state, which are "sleeping", and how many threads are currently being occupied. Also shown here is your CPU (processor) usage, including the percent being used up by you, by the system, and what's sitting idle.

The next section (shown in green) is devoted to memory usage (both physical memory and virtual memory). The last section (shown in blue) shows network information (packets being sent in and out) and hard drive information (the amount of data being read and written).

The bottom part of the view (shown in yellow) will show you processing currently being executed on your system. You will be able to see the PID (Process ID), the command or application being run, the percentage load on the CPU by the app, the execution time, how many threads are being used by the applications, and more.

Kill a Process

If you spot an application that is hogging up all of the resources from your Mac, you may want to stop it from running (or “kill the process", as it’s often referred to). This may be an unresponsive application, or perhaps an application that you started running and then forgot about. Either way, you can stop the process by entering the following command into a new Terminal window:

kill -9 PID

Replace PID in the above command with the process ID of the process that you’d like to stop running (this can be obtained by running the top command again). After pressing enter, the application will stop running.

If you don’t have sufficient privileges to stop the running application, you may need to place “sudo” in front of the above command (so, it would read “sudo kill -9 PID”). When doing this, you will be prompted to enter your administrator password before the application will quit.

Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article's author, Cory Bohon on Twitter.