{"id":843,"date":"2017-03-18T18:34:07","date_gmt":"2017-03-18T13:04:07","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=843"},"modified":"2018-10-24T13:01:17","modified_gmt":"2018-10-24T07:31:17","slug":"difference-nohup-disown","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/difference-nohup-disown\/","title":{"rendered":"Difference between nohup, disown and &#038;"},"content":{"rendered":"<h2 id=\"command\"><span style=\"color: #ff6600;\"><strong><command> :<\/strong><\/span><\/h2>\n<p>Runs the process within the Terminal\u2019s current <a href=\"https:\/\/www.wikitechy.com\/technology\/write-loop-using-bash\/\" target=\"_blank\" rel=\"noopener\">bash<\/a> instance, in the background (i.e. the process is listed as a bash background job and stdin, stdout and stderr are still bound to the terminal); not immune to hangups;<\/p>\n<h2 id=\"command-disown\"><span style=\"color: #808000;\"><strong><command> & disown:<\/strong><\/span><\/h2>\n<p>Runs the process within the Terminal\u2019s current bash instance, in the background, but the process is detached from the bash\u2019s jobs\u2019 list (i.e. the process is not listed as a bash foreground \/ background job and stdin, stdout and stderr are still bound to the terminal); immune to hangups;<\/p>\n<h2 id=\"nohup-command-disown\"><span style=\"color: #800080;\"><strong>nohup <command> & disown:<\/strong><\/span><\/h2>\n<ul>\n<li>Runs the process within the Terminal\u2019s current bash instance, in the background, but the process is detached from the bash\u2019s jobs\u2019 list (i.e. the process is not listed as a bash foreground \/ background job and stdin, stdout and stderr are not still bound to the terminal);immune to hangups;<\/li>\n<li><strong>& <\/strong>puts the job in the background, that is, makes it block on attempting to read input, and makes the <a href=\"https:\/\/www.wikitechy.com\/tutorials\/linux\/how-to-prompt-user-for-yes-no-cancel-input-in-a-linux-shell-script\" target=\"_blank\" rel=\"noopener\">shell<\/a> not wait for its completion.<\/li>\n<li><strong>disown <\/strong>removes the process from the shell\u2019s job control, but still leaves it connected to the terminal. One of the results is that the shell won\u2019t send it a SIGHUP. Obviously, it can only be applied to background jobs, because you cannot enter it when a foreground job is running.<\/li>\n<li><strong>nohup <\/strong>disconnects the process from the terminal, redirects its output to nohup.out and shields it from SIGHUP. One of the effects (the naming one) is that the process won\u2019t receive any sent NOHUP. It is completely independent from job control and could in principle be used also for foreground jobs.<\/li>\n<li>Using & causes the program to run in the background, so you\u2019ll get a new shell <a href=\"https:\/\/www.wikitechy.com\/technology\/10-useful-command-prompt-tricks-might-not-know\/\" target=\"_blank\" rel=\"noopener\">prompt<\/a> instead of blocking until the program ends.<\/li>\n<li><strong>nohup, disown<\/strong> are largely unrelated; they suppress SIGHUP (hangup) signals so the program isn\u2019t automatically killed when the controlling terminal is closed. nohup does this when the begining.<\/li>\n<li>If you don\u2019t nohup a job when it begins, you can use disown to modify a running job; with no arguments it modifies the current job, which is the one that was just backgrounded<\/li>\n<li>Using the ampersand (&) will run the command in a child process (child to the current bash session). But, when you exit the session, all child processes will be killed.<\/li>\n<li>using nohup + ampersand (&) will do the same thing, except that when the <a href=\"https:\/\/www.wikitechy.com\/technology\/php-check-php-session-already-started\/\" target=\"_blank\" rel=\"noopener\">session<\/a> ends, the parent of the child process will be changed to \u201c1\u201d which is the \u201cinit\u201d process, thus preserving the child from being killed.<\/li>\n<li>The nohup <a href=\"https:\/\/www.wikitechy.com\/technology\/using-linux-echo-command-output-text-screen\/\" target=\"_blank\" rel=\"noopener\">command<\/a> is a signal masking utility and catches the hangup signal. Where as ampersand doesn\u2019t catch the hang up signals.<\/li>\n<\/ul>\n[ad type=\u201dbanner\u201d]\n","protected":false},"excerpt":{"rendered":"<p>: Runs the process within the Terminal\u2019s current bash instance, in the background (i.e. the process is listed as a bash background job and stdin, stdout and stderr are still bound to the terminal); not immune to hangups; &#038; disown: Runs the process within the Terminal\u2019s current bash instance, in the background, but the process [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1331],"tags":[1597,1599,1595,1591,1594,1593,1596,1587,1589,1592,1598,1590,1588],"class_list":["post-843","post","type-post","status-publish","format-standard","hentry","category-unix","tag-bash-differences-between-disown-and-nohup","tag-detach-processes-with-disown-and-nohup","tag-disown-wont-take-h-option","tag-how-can-i-close-a-terminal-without-killing-the-command-running-in-it","tag-how-can-i-turn-the-behavior-of-gedit-something-disown-into-the-default-behavior-when-calling-gedit-from-the-command-line","tag-how-to-open-a-process-from-terminal-without-becoming-child-process","tag-is-there-a-difference-between-nohup-and-nohup-in-a-screen","tag-related-queries-how-to-make-a-program-which-run-from-shell-still-live-after-close-terminal","tag-running-multiple-nohup-commands-in-background","tag-what-is-the-difference-between-starting-a-command-with-nohup-and","tag-whats-the-difference-between-nohup-and-ampersand","tag-when-do-you-need-nohup-if-youre-already-forking-using","tag-why-is-chromium-browser-killed-when-i-close-the-terminal-despite-nohup"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=843"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/843\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}