{"id":5100,"date":"2015-08-13T14:09:13","date_gmt":"2015-08-13T06:09:13","guid":{"rendered":"http:\/\/rmohan.com\/?p=5100"},"modified":"2015-08-13T14:09:13","modified_gmt":"2015-08-13T06:09:13","slug":"process-id-attached-with-particular-port-in-sunos","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=5100","title":{"rendered":"process id attached with particular port in sunos"},"content":{"rendered":"<pre><code>pfiles \/proc\/* 2&gt;\/dev\/null | nawk '\r\n\/^[0-9]*:\/ { pid=$0 }\r\n\/port: 7085$\/ { printf(\"%s %s\\n\",pid,$0);}'\r\n\r\n<\/code><\/pre>\n<p>I would try something like:<\/p>\n<pre><code>$ lsof -i :7085<\/code><\/pre>\n<pre><code>\r\n\r\n<\/code><\/pre>\n<p>PCP is a script that enables administrators to see what open TCP ports are in use on a Solaris system. It maps ports to PIDs and vice versa. It accepts wildcards and will also show at a glance all open ports and their corresponding PIDs. It is nice script gives a very fine out put. Just try it.<\/p>\n<p>Example:<span class=\"Apple-converted-space\">\u00a0<\/span><code>#pcp -p PORT_NUMBER or #pcp -P PROCESS_ID<\/code><\/p>\n<pre><code>#!\/usr\/bin\/ksh\r\n#\r\n# # PCP (PID con Port)\r\n# v1.10 08\/10\/2010 Sam Nelson sam @ unix.ms\r\n#\r\n# If you have a Solaris 8, 9 or 10 box and you can't\r\n# install lsof, try this. It maps PIDS to ports and vice versa.\r\n# It also shows you which peers are connected on which port.\r\n# Wildcards are accepted for -p and -P options.\r\n#\r\n# Many thanks Daniel Trinkle trinkle @ cs.purdue.edu\r\n# for the help, much appreciated.\r\n\r\n#\r\ni=0\r\nwhile getopts :p:P:a opt\r\ndo\r\ncase \"${opt}\" in\r\np ) port=\"${OPTARG}\";i=3;;\r\nP ) pid=\"${OPTARG}\";i=3;;\r\na ) all=all;i=2;;\r\nesac\r\ndone\r\nif [ $OPTIND != $i ]\r\nthen\r\necho &gt;&amp;2 \"usage: $0 [-p PORT] [-P PID] [-a] (Wildcards OK) \"\r\nexit 1\r\nfi\r\nshift `expr $OPTIND - 1`\r\nif [ \"$port\" ]\r\nthen\r\n# Enter the port number, get the PID\r\n#\r\nport=${OPTARG}\r\necho \"PID\\tProcess Name and Port\"\r\necho \"_________________________________________________________\"\r\nfor proc in `ptree -a | awk '\/ptree\/ {next} {print $1};'`\r\ndo\r\nresult=`pfiles $proc 2&gt; \/dev\/null| egrep \"port: $port$\"`\r\nif [ ! -z \"$result\" ]\r\nthen\r\nprogram=`ps -fo comm= -p $proc`\r\necho \"$proc\\t$program\\t$port\\n$result\"\r\necho \"_________________________________________________________\"\r\nfi\r\ndone\r\nelif [ \"$pid\" ]\r\nthen\r\n# Enter the PID, get the port\r\n#\r\npid=$OPTARG\r\n# Print out the information\r\necho \"PID\\tProcess Name and Port\"\r\necho \"_________________________________________________________\"\r\nfor proc in `ptree -a | awk '\/ptree\/ {next} $1 ~ \/^'\"$pid\"'$\/ {print $1};'`\r\ndo\r\nresult=`pfiles $proc 2&gt; \/dev\/null| egrep port:`\r\nif [ ! -z \"$result\" ]\r\nthen\r\nprogram=`ps -fo comm= -p $proc`\r\necho \"$proc\\t$program\\n$result\"\r\necho \"_________________________________________________________\"\r\nfi\r\ndone\r\nelif [ $all ]\r\nthen\r\n# Show all PIDs, Ports and Peers\r\n#\r\necho \"PID\\tProcess Name and Port\"\r\necho \"_________________________________________________________\"\r\nfor proc in `ptree -a | sort -n | awk '\/ptree\/ {next} {print $1};'`\r\ndo\r\nout=`pfiles $proc 2&gt;\/dev\/null| egrep \"port:\"`\r\nif [ ! -z \"$out\" ]\r\nthen\r\nname=`ps -fo comm= -p $proc`\r\necho \"$proc\\t$name\\n$out\"\r\necho \"_________________________________________________________\"\r\nfi\r\ndone\r\nfi\r\nexit 0<\/code><\/pre>\n<pre><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>pfiles \/proc\/* 2&gt;\/dev\/null | nawk &#8216; \/^[0-9]*:\/ { pid=$0 } \/port: 7085$\/ { printf(&#8220;%s %s\\n&#8221;,pid,$0);}&#8217; <\/p>\n<p>I would try something like:<\/p>\n<p> $ lsof -i :7085 <\/p>\n<p>PCP is a script that enables administrators to see what open TCP ports are in use on a Solaris system. It maps ports to PIDs and vice versa. It accepts wildcards [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5100"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5100"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5100\/revisions"}],"predecessor-version":[{"id":5101,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5100\/revisions\/5101"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}