In UNIX OS, how can I find the port number when i know the process name or pid ?
Asked
Active
Viewed 4.6k times
13

user1857216
- 147
- 1
- 1
- 3
2 Answers
19
netstat -pl | grep NAME_OR_PID

Chris Eberle
- 47,994
- 12
- 82
- 119
-
specifying the -p flag is usually followed by the protocol – Emmanuel John Jan 12 '14 at 22:31
-
@unekwu incorrect. Go read the man page. `-p, --program: Show the PID and name of the program to which each socket belongs.` You're thinking of `--protocol` which is different. – Chris Eberle Jan 14 '14 at 03:30
-
1I get `netstat: l: unknown or uninstrumented protocol` when I run this on my computer – Emmanuel John Jan 14 '14 at 05:45
-
@unekwu then you have a non-standard netstat implementation. Mine is part of the "net-tools 2.10 alpha" suite, running under Arch Linux. – Chris Eberle Jan 14 '14 at 21:44
-
2I see. Its different for OSX. I tried to upvote but it says I can't upvote until it is edited. If you include it doesn't work for mac, I'll upvote again. – Emmanuel John Jan 17 '14 at 14:27