{"id":93,"date":"2010-03-10T16:43:44","date_gmt":"2010-03-10T14:43:44","guid":{"rendered":"http:\/\/www.zagura.ro\/index.php\/2010\/03\/10\/how-to-programmatically-dump-the-threads-list-of-a-running-java-process-in-bash\/"},"modified":"2010-03-10T16:43:44","modified_gmt":"2010-03-10T14:43:44","slug":"how-to-programmatically-dump-the-threads-list-of-a-running-java-process-in-bash","status":"publish","type":"post","link":"https:\/\/www.zagura.com\/blog\/index.php\/2010\/03\/10\/how-to-programmatically-dump-the-threads-list-of-a-running-java-process-in-bash\/","title":{"rendered":"How to programmatically dump the threads list of a running java process in bash"},"content":{"rendered":"<p>It seems that jdb cannot accept commands from command line, so we must use <a href=\"http:\/\/linux.die.net\/man\/1\/expect\">expect<\/a>.<br \/>\nI created the following expect script <strong>dumpthreads<\/strong><br \/>\nYou can use it like:<br \/>\n<strong>dumpthreads<\/strong>   <em>java_process_pid<\/em><br \/>\n<code><br \/>\n#!\/usr\/bin\/expect<br \/>\nset pid [lindex $argv 0];<br \/>\nspawn jdb -connect sun.jvm.hotspot.jdi.SAPIDAttachingConnector:pid=$pid;<br \/>\nexpect \">\";<br \/>\nsend \"threads\\n\";<br \/>\nexpect \">\";<br \/>\nsend \"quit\\n\";<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>It seems that jdb cannot accept commands from command line, so we must use expect. I created the following expect script dumpthreads You can use it like: dumpthreads java_process_pid #!\/usr\/bin\/expect set pid [lindex $argv 0]; spawn jdb -connect sun.jvm.hotspot.jdi.SAPIDAttachingConnector:pid=$pid; expect &#8220;>&#8221;; send &#8220;threads\\n&#8221;; expect &#8220;>&#8221;; send &#8220;quit\\n&#8221;;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,15,2,10],"tags":[],"_links":{"self":[{"href":"https:\/\/www.zagura.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/93"}],"collection":[{"href":"https:\/\/www.zagura.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zagura.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zagura.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zagura.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=93"}],"version-history":[{"count":0,"href":"https:\/\/www.zagura.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/93\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zagura.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=93"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zagura.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=93"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zagura.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=93"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}