{"id":3582,"date":"2014-09-17T06:12:18","date_gmt":"2014-09-17T06:12:18","guid":{"rendered":"http:\/\/www.oratraining.com\/blog\/?p=3582"},"modified":"2014-09-18T06:13:25","modified_gmt":"2014-09-18T06:13:25","slug":"find-linuxsolaris-process-using-port-number","status":"publish","type":"post","link":"https:\/\/www.oratraining.com\/blog\/2014\/09\/find-linuxsolaris-process-using-port-number\/","title":{"rendered":"Find Linux\/Solaris process using port number"},"content":{"rendered":"<p>Often we\u00a0encounter errors\u00a0that a particular required port is already being used by another process.<\/p>\n<p>The\u00a0steps to find out which process is using a particular port number is relatively easy in Linux but it can be a bit tricky on Solaris.<\/p>\n<p>Let us\u00a0see how to find process PID from port number<\/p>\n<h3><span style=\"color: #993300;\"><strong>1. For Linux Operating System<\/strong><\/span><\/h3>\n<p>There are 3 ways to find this out depending on\u00a0which package is installed in your OS.<\/p>\n<p><span style=\"color: #333399;\"><strong>i) fuser<\/strong><\/span><\/p>\n<p>The syntax of using fuser is<br \/>\n<strong>fuser &lt;port&gt;\/&lt;protocol&gt;<\/strong><\/p>\n<p>For example, to find which process is using TCP port 23792,<\/p>\n<blockquote><p>root@dbhost1 etc]# fuser 23792\/tcp<br \/>\n23792\/tcp: 17006<\/p><\/blockquote>\n<p><span style=\"color: #333399;\"><strong>ii) netstat<\/strong><\/span><\/p>\n<p>The syntax of using netstat to find process ID from port is<br \/>\n<strong>netstat\u00a0-tulpn | grep\u00a0&lt;port&gt;<\/strong><\/p>\n<p>For example, to find which process is using TCP port 23792,<\/p>\n<blockquote><p>[root@dbhost1 etc]# netstat -tulpn | grep 23792<br \/>\ntcp 0 0 :::23792 :::* LISTEN 17006\/java<\/p><\/blockquote>\n<p><span style=\"color: #333399;\"><strong>iii) lsof<\/strong><\/span><\/p>\n<p>The syntax of using lsof\u00a0to find process ID from port is<br \/>\n<strong>lsof -i &lt;protocol&gt;:&lt;port&gt;<\/strong><\/p>\n<p>For example, to find which process is using TCP port 23792,<\/p>\n<blockquote><p>[root@dbhost1 etc]# lsof -i tcp:23792<br \/>\nCOMMAND PID USER FD TYPE DEVICE SIZE\/OFF NODE NAME<br \/>\njava 17006 grid 170u IPv6 594633 0t0 TCP *:23792 (LISTEN)<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h3><span style=\"color: #993300;\"><strong>2. For Solaris Operating System<\/strong><\/span><\/h3>\n<p>Since these\u00a0utilities are generally not installed or available by default on Solaris operating system, we\u00a0use following easy script to find PID from port number.<\/p>\n<p>Note: Save this script as check_port.sh and grant execute permissions using chmod +x to this script.<\/p>\n<blockquote><p>#!\/bin\/bash<\/p>\n<p># Get the process which listens on port<\/p>\n<p># $1 is the port we are looking for<\/p>\n<p>if [ $# -lt 1 ]<br \/>\nthen<br \/>\necho &#8220;Please provide a port number parameter for this script&#8221;<br \/>\necho &#8220;e.g. $0 22&#8221;<br \/>\nexit<br \/>\nfi<\/p>\n<p>echo &#8220;Greping for your port, please be patient (CTRL+C breaks) &#8230; &#8221;<\/p>\n<p>for i in `ls \/proc`<br \/>\ndo<br \/>\npfiles $i | grep AF_INET | grep $1<br \/>\nif [ $? -eq 0 ]<br \/>\nthen<br \/>\necho Is owned by pid $i<br \/>\nfi<br \/>\ndone<\/p><\/blockquote>\n<p>Now\u00a0the syntax of using this script is<br \/>\n.\/check_port.sh &lt;port number&gt;<\/p>\n<p>For example, to find which process is using TCP port 1521,<\/p>\n<blockquote><p>root@hostname # .\/check_port.sh 1521<br \/>\nGreping for your port, please be patient (CTRL+C breaks) &#8230;<br \/>\nsockname: AF_INET 10.21.26.24 port: 1521<br \/>\nIs owned by pid 10279<br \/>\n^C<\/p><\/blockquote>\n<p>That&#8217;s it. Please feel free to add\/suggest any new utilities to other users in comment section below.<\/p>\n<p>Happy learning !<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often we\u00a0encounter errors\u00a0that a particular required port is already being used by another process. The\u00a0steps to find out which process is using a particular port number is relatively easy in Linux but it can be a bit tricky on Solaris. Let us\u00a0see how to find process PID from port number 1. For Linux Operating System [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3582","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/posts\/3582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/comments?post=3582"}],"version-history":[{"count":1,"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/posts\/3582\/revisions"}],"predecessor-version":[{"id":3583,"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/posts\/3582\/revisions\/3583"}],"wp:attachment":[{"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/media?parent=3582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/categories?post=3582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/tags?post=3582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}