OS X Process-Fu 101

OSX is of course a variety of BSD Unix, not Linux. Often is the case where Linux commands either don’t work, or don’t give the same results on OSX as they do on Linux.

For example, a basic


will give you a long list of the processes making network connections on your box. On Linux, various command line options can help you drill down from there, to get the answers to more specific queries. On OSX, those same queries don’t give you the answers you’re seeking.

This isn’t a compare and contrast article between Linux and OSX. Instead, I’m just noting various commands that can give answers to some basic questions.

On OSX, for example, to get an answer to the question: “What process is running on port 50224?” we would use:

sudo lsof -Pn | grep 50224

This will give you a list of everything connected to port 50224, sans any kind of headings.

A much more abbreviated command that will give you essentially the same things, but with column headings as well, is:

sudo lsof -i :50224

Now, suppose we wanted to get a listing of all processes making network connections from our (OSX) box, including their Command Name, PID, Type of connection, and the Port they’re listing to (along with other info)?

lsof -i -P | less

This command gives all this, with a heading at the top. Piping to less is optional.

Another thing that often comes up is finding out if a certain process is running, let’s call it foo.

ps aux | grep foo

This will show whether or not foo is indeed running, and if it is, what its PID is. From there, if foo is unwanted, it can be killed with:

kill -9 foo

Just as a note: in some cases, you may need to:


the above commands.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s