{"id":3797,"date":"2014-06-20T11:22:26","date_gmt":"2014-06-20T16:22:26","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=3797"},"modified":"2014-06-20T11:22:26","modified_gmt":"2014-06-20T16:22:26","slug":"where-is-a-given-thread-connecting","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2014\/06\/20\/where-is-a-given-thread-connecting\/","title":{"rendered":"Where is a given thread connecting?"},"content":{"rendered":"<p>We start by getting the PID of our running JVM&#8230;<\/p>\n<pre>\r\n-bash-4.1$ jps\r\n29527 Main\r\n3560 Jps\r\n<\/pre>\n<p>&#8230;then we print each lightweight process (threads in our JVM) in which we are interested.  In our case, these are threads with zafu in the name, but it could be anything in which you are interested&#8230;<\/p>\n<pre>\r\n-bash-4.1$ for f in $(jstack 29527 | awk '$0 ~ \"zafu.*nid=\" {i=0;while (++i <= NF) {if ($i ~ \"nid=\") {split($i,t,\"=\");print t[2]}}}' | grep 0x); do p=$(printf \"%i\" $f); ps -eLf | awk -v p=$p '$4 == p'; done | awk '{print $4,$7}'\r\n31215 04:23\r\n22000 Jun19\r\n21159 Jun19\r\n20715 Jun19\r\n20682 Jun19\r\n20526 Jun19\r\n20103 Jun19\r\n20063 Jun19\r\n19755 Jun19\r\n19057 Jun19\r\n18153 Jun19\r\n27228 Jun19\r\n25826 Jun19\r\n6303 Jun19\r\n<\/pre>\n<p>...we then pick one of these, and see that it is waiting to receive some data on a network socket...<\/p>\n<pre>\r\n-bash-4.1$ strace -p 31215\r\nProcess 31215 attached - interrupt to quit\r\nrecvfrom(373, ^C <unfinished ...>\r\nProcess 31215 detached\r\n<\/pre>\n<p>...so we get the network socket associated with this file descriptor...<\/p>\n<pre>\r\n-bash-4.1$ ls -lrt \/proc\/29527\/fd | awk '$(NF - 2) == 373 {print $NF}'\r\nsocket:[833215397]\r\n<\/pre>\n<p>...and see the (masked) IP address to which we are connecting...<\/p>\n<pre>\r\n-bash-4.1$ netstat -eanp | grep 833215397\r\ntcp        0      0 12.8.6.1:47977           4.28.7.10:2222          ESTABLISHED 11006      833215397  29527\/java\r\n-bash-4.1$\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We start by getting the PID of our running JVM&#8230; -bash-4.1$ jps 29527 Main 3560 Jps &#8230;then we print each lightweight process (threads in our JVM) in which we are interested. In our case, these are threads with zafu in&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2014\/06\/20\/where-is-a-given-thread-connecting\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[25,28],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/3797"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=3797"}],"version-history":[{"count":5,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/3797\/revisions"}],"predecessor-version":[{"id":3803,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/3797\/revisions\/3803"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=3797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=3797"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=3797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}