{"id":392,"date":"2010-09-14T21:57:54","date_gmt":"2010-09-14T19:57:54","guid":{"rendered":"http:\/\/gcolpart.evolix.net\/blog21\/?p=392"},"modified":"2010-09-15T14:13:54","modified_gmt":"2010-09-15T12:13:54","slug":"capture-inputoutput-of-a-process-with-gdb","status":"publish","type":"post","link":"https:\/\/gcolpart.evolix.net\/blog21\/capture-inputoutput-of-a-process-with-gdb\/","title":{"rendered":"Capture input\/output of a process with gdb"},"content":{"rendered":"<p>My tip of day. When you lose control of a process (for example with a process launched with <a href=\"http:\/\/www2.research.att.com\/~gsf\/man\/man1\/disown.html\">disown<\/a> or, another example, when you close your SSH terminal with &#8220;unsynced&#8221; mutt), thanks gdb.<\/p>\n<pre>$ tty\r\n\/dev\/pts\/13\r\n$ gdb --pid=`pidof mutt`\r\n(gdb) call close(0)\r\n(gdb) call close(1)\r\n(gdb) call close(2)\r\n(gdb) call open(\"\/dev\/pts\/13\", 2, 0)\r\n(gdb) call dup(0)\r\n(gdb) call dup(0)\r\n(gdb) detach\r\nDetaching from program: \/usr\/bin\/mutt-org, process 2932<\/pre>\n<p>Thanks to <a href=\"http:\/\/superuser.com\/questions\/50058\/after-the-fact-remote-nohup-with-tcsh\/50077#50077\">this comment on superuser.com<\/a> for the original idea.<\/p>\n<p>Edit: correction on dup() calls. Thanks to Peter Pentchev for his explanation in comments.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My tip of day. When you lose control of a process (for example with a process launched with disown or, another example, when you close your SSH terminal with &#8220;unsynced&#8221; mutt), thanks gdb. $ tty \/dev\/pts\/13 $ gdb &#8211;pid=`pidof mutt` (gdb) call close(0) (gdb) call close(1) (gdb) call close(2) (gdb) call open(&#8220;\/dev\/pts\/13&#8221;, 2, 0) (gdb) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3],"tags":[117,148,115,114,116],"class_list":["post-392","post","type-post","status-publish","format-standard","hentry","category-debian","category-english","tag-bash","tag-debian","tag-gdb","tag-mutt","tag-shell"],"_links":{"self":[{"href":"https:\/\/gcolpart.evolix.net\/blog21\/wp-json\/wp\/v2\/posts\/392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gcolpart.evolix.net\/blog21\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gcolpart.evolix.net\/blog21\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gcolpart.evolix.net\/blog21\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gcolpart.evolix.net\/blog21\/wp-json\/wp\/v2\/comments?post=392"}],"version-history":[{"count":7,"href":"https:\/\/gcolpart.evolix.net\/blog21\/wp-json\/wp\/v2\/posts\/392\/revisions"}],"predecessor-version":[{"id":398,"href":"https:\/\/gcolpart.evolix.net\/blog21\/wp-json\/wp\/v2\/posts\/392\/revisions\/398"}],"wp:attachment":[{"href":"https:\/\/gcolpart.evolix.net\/blog21\/wp-json\/wp\/v2\/media?parent=392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gcolpart.evolix.net\/blog21\/wp-json\/wp\/v2\/categories?post=392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gcolpart.evolix.net\/blog21\/wp-json\/wp\/v2\/tags?post=392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}