Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I find the process id and stop the process that is running on port 8080 on a Mac?

On Ubuntu this works:

ps -aux

and I can find the process and run:

kill -9 pid

ps -aux didn't seem to work, how can I do this on Mac OS X Lion?

share|improve this question
    
2  
No. No. No. Please, please, please do not use kill -9 pid until after you've tried just kill pid. Many processes will have signal handlers which will clean up their use of resources, cleanly close connections and other pre-shutdown tasks. If you kill with -9, the process dies immediately without doing the cleanup. Killing without -9 will work most of the time. –  Doug Harris Jan 30 '12 at 19:00
add comment

4 Answers 4

For historical reasons, ps's options are a tangled and inconsistent mess. On OS X Lion, any of these should work:

ps -ax
ps -e
ps aux # this displays in a different format

I don't have an ubuntu box handy to test, but according to the man page, ps -aux isn't the right way to do it there either:

Note that "ps -aux" is distinct from "ps aux". The POSIX and UNIX
standards require that "ps -aux" print all processes owned by a user
named "x", as well as printing all processes that would be selected by
the -a option. If the user named "x" does not exist, this ps may
interpret the command as "ps aux" instead and print a warning. This
behavior is intended to aid in transitioning old scripts and habits. It
is fragile, subject to change, and thus should not be relied upon.
share|improve this answer
add comment

Use Activity Monitor.

Applications -> Utilities -> Activity Monitor

share|improve this answer
add comment

I believe ps -ef on Mac is nearly equivalent to ps -aux on linux.

To get what PID has port 8080 in use: lsof -P | grep 8080

The fields map out to:

[mini-nevie:~] nevinwilliams% lsof -P | head -1
COMMAND     PID          USER   FD     TYPE             DEVICE  SIZE/OFF    NODE NAME

I started up ttcp -rs which listens on port 5001.

mini-nevie:~] nevinwilliams% lsof -P | grep 5001
ttcp      27999 nevinwilliams    3u    IPv4 0xb70c1f66028d6961       0t0     TCP *:5001 (LISTEN)

and indeed, PID 27999 corresponds to the PID of the ttcp process I launched.

share|improve this answer
    
You can also use ps aux (without the dash) on OS X. ps -ef includes different columns and uses a different format. –  Lri May 2 '13 at 7:21
    
I happen not to currently have a linux login to compare; Years ago, IIRC, if -aux didn't give the expected output on a particular flavour of unix, then -ef would... AIX, Linux, SunOS used -aux, BSD, Solaris needed -ef for compatibility; I forget if IRIX was -aux or -ef. I don't recall what the major difference in the respective systems were... –  Nevin Williams May 3 '13 at 3:27
    
OS X's aux and Ubuntu's aux and -aux use the same format, but Ubuntu's -aux prints a warning at the start. –  Lri May 3 '13 at 7:37
    
Ahha... The split was between SysV and BSD implementations. –  Nevin Williams May 3 '13 at 15:48
add comment

If you wish to find and kill all processes which conform to a string, you can also use the following on a Mac OSX:

ps aux | grep <string> | awk '{print $1}' | <sudo> xargs kill -9

Basically what this will do is that it will find (grep) all the processes currently running on your system matching the , AWK gets the PID, which in the PS command is the second column and the last one takes the arguments from AWK and kills the processes.

Use SUDO, only if the current user does not have some rights to kill a process and if you have SUDO access on your system.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.