{"id":788,"date":"2025-09-09T19:53:02","date_gmt":"2025-09-09T14:23:02","guid":{"rendered":"https:\/\/www.cyberaka.com\/?p=788"},"modified":"2025-09-09T19:53:05","modified_gmt":"2025-09-09T14:23:05","slug":"running-background-processes-in-linux-with-nohup-and","status":"publish","type":"post","link":"https:\/\/www.cyberaka.com\/?p=788","title":{"rendered":"Running Background Processes in Linux with nohup and &#038;"},"content":{"rendered":"\n<p>Have you ever started a long-running script in your terminal, only to lose all progress when the session closed? Or maybe you wanted to keep a process running in the background while continuing to use the terminal?<\/p>\n\n\n\n<p>That\u2019s where&nbsp;nohup&nbsp;and&nbsp;&amp;&nbsp;come in handy.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69f72b63d620a\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69f72b63d620a\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.cyberaka.com\/?p=788\/#What_Are_nohup_and\" >What Are\u00a0nohup\u00a0and\u00a0&amp;?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.cyberaka.com\/?p=788\/#Basic_Usage\" >Basic Usage<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.cyberaka.com\/?p=788\/#Breakdown\" >Breakdown:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.cyberaka.com\/?p=788\/#Monitoring_the_Output\" >Monitoring the Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.cyberaka.com\/?p=788\/#Cleaning_Up_Stopping_the_Process\" >Cleaning Up: Stopping the Process<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.cyberaka.com\/?p=788\/#Pro_Tips\" >Pro Tips<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.cyberaka.com\/?p=788\/#Final_Thoughts\" >Final Thoughts<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Are_nohup_and\"><\/span>What Are\u00a0nohup\u00a0and\u00a0&amp;?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>nohup: Short for\u00a0<em>no hang up<\/em>, it allows a command to keep running even after you log out or close the terminal.<\/li>\n\n\n\n<li>&amp;: Sends the command to the background, freeing up your terminal for other tasks.<\/li>\n<\/ul>\n\n\n\n<p>Together, they\u2019re a powerful combo for running persistent background processes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Basic_Usage\"><\/span><strong>Basic Usage<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here\u2019s the magic one-liner:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nohup your_command > output.log 2>&amp;1 &amp;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Breakdown\"><\/span>Breakdown:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>your_command<\/code>: The script or program you want to run.<\/li>\n\n\n\n<li><code>> output.log<\/code>: Redirects standard output to a file.<\/li>\n\n\n\n<li><code>2>&amp;1<\/code>: Redirects standard error to the same file.<\/li>\n\n\n\n<li><code>&amp;<\/code>: Runs the command in the background.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Monitoring_the_Output\"><\/span>Monitoring the Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To watch the output in real-time:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail\u00a0-f\u00a0output.log<\/code><\/pre>\n\n\n\n<p>This is especially useful for debugging or tracking progress.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Cleaning_Up_Stopping_the_Process\"><\/span>Cleaning Up: Stopping the Process<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To stop the background process:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Find the process ID (PID):<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>ps\u00a0aux\u00a0|\u00a0grep\u00a0your_command<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Kill it:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>kill &lt;PID><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Or, if you want to be sure:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>kill -9 &lt;PID><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Pro_Tips\"><\/span>Pro Tips<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you forget to redirect output,\u00a0<code>nohup<\/code>\u00a0will write to\u00a0<code>nohup.out<\/code>\u00a0by default. <\/li>\n\n\n\n<li>You can check running background jobs with:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>jobs<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To bring a background job to the foreground:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>fg\u00a0%1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Final_Thoughts\"><\/span>Final Thoughts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Using\u00a0<code>nohup<\/code>\u00a0and\u00a0<code>&amp;<\/code>\u00a0is a simple yet powerful way to manage long-running or persistent processes in Linux. Whether you&#8217;re deploying a server, training a model, or crunching data, this trick can save you time and frustration.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever started a long-running script in your terminal, only to lose all progress when the session closed? Or maybe you wanted to keep a process running in the background while continuing to use the terminal? That\u2019s where&nbsp;nohup&nbsp;and&nbsp;&amp;&nbsp;come in handy. What Are\u00a0nohup\u00a0and\u00a0&amp;? Together, they\u2019re a powerful combo for running persistent background processes. Basic Usage [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,35,24],"tags":[],"class_list":["post-788","post","type-post","status-publish","format-standard","hentry","category-linux-os","category-mac-os","category-tips-and-tricks"],"_links":{"self":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts\/788","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=788"}],"version-history":[{"count":1,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts\/788\/revisions"}],"predecessor-version":[{"id":789,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts\/788\/revisions\/789"}],"wp:attachment":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}