{"id":906,"date":"2013-06-09T23:04:02","date_gmt":"2013-06-10T05:04:02","guid":{"rendered":"http:\/\/jaredrobinson.com\/blog\/?p=906"},"modified":"2013-06-09T23:04:02","modified_gmt":"2013-06-10T05:04:02","slug":"debugging-shell-scripts-user-interfaces-and-compiled-programs-on-linux","status":"publish","type":"post","link":"https:\/\/jaredrobinson.com\/blog\/debugging-shell-scripts-user-interfaces-and-compiled-programs-on-linux\/","title":{"rendered":"Debugging shell scripts, User Interfaces and compiled programs on Linux"},"content":{"rendered":"<p>When I want to debug a shell\/bash shell script, I add the following to the script:<\/p>\n<p><code><br \/>\nset -x<br \/>\nexport PS4='+(${BASH_SOURCE}:${LINENO}): '<br \/>\n<\/code><\/p>\n<p>Other times, I export PS4 in my interactive shell, and run the script with &#8220;bash -x \/path\/to\/script&#8221;. More bash script debugging tips are here: <a href=\"http:\/\/wiki.bash-hackers.org\/scripting\/debuggingtips\">http:\/\/wiki.bash-hackers.org\/scripting\/debuggingtips<\/a><\/p>\n<p>When I want to see what commands are being run on a Linux machine by a higher-level user interface, I turn to <a href=\"https:\/\/github.com\/pturmel\/startmon\">startmon<\/a>. It shows me every process created, along with its arguments. This can be useful for figuring out how a CD\/DVD-creation program calls wodim\/cdrecord, or how it mounts a drive.<\/p>\n<p>When I don&#8217;t have source code to a compiled program, and I want to see what system calls it is making, and check into why it might be failing to run, I use <a href=\"http:\/\/en.wikipedia.org\/wiki\/Strace\">strace<\/a>.<\/p>\n<p>When I want to find out which programs are preventing me from unmounting a DVD or a USB flash drive, I use &#8216;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Lsof\">lsof<\/a>&#8216;, which is available for nearly every UNIX-like operating system.<\/p>\n<p>When I want to know what programs are consuming the most disk I\/O and making things go slow, I use &#8216;top&#8217; to see the top-memory consumers, and whether they have a high number of page faults. I use &#8216;iotop&#8217; as well.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I want to debug a shell\/bash shell script, I add the following to the script: set -x export PS4=&#8217;+(${BASH_SOURCE}:${LINENO}): &#8216; Other times, I export PS4 in my interactive shell, and run the script with &#8220;bash -x \/path\/to\/script&#8221;. More bash script debugging tips are here: http:\/\/wiki.bash-hackers.org\/scripting\/debuggingtips When I want to see what commands are being &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/jaredrobinson.com\/blog\/debugging-shell-scripts-user-interfaces-and-compiled-programs-on-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Debugging shell scripts, User Interfaces and compiled programs on Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,17],"tags":[],"class_list":["post-906","post","type-post","status-publish","format-standard","hentry","category-linux","category-tech"],"_links":{"self":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/906","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/comments?post=906"}],"version-history":[{"count":3,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/906\/revisions"}],"predecessor-version":[{"id":909,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/906\/revisions\/909"}],"wp:attachment":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/media?parent=906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/categories?post=906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/tags?post=906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}