{"id":13268,"date":"2019-04-01T10:19:08","date_gmt":"2019-04-01T10:19:08","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13268"},"modified":"2019-04-01T10:19:08","modified_gmt":"2019-04-01T10:19:08","slug":"5-ways-to-keep-remote-ssh-sessions-and-processes-running-after-disconnection","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/5-ways-to-keep-remote-ssh-sessions-and-processes-running-after-disconnection\/","title":{"rendered":"5 Ways to Keep Remote SSH Sessions and Processes Running After Disconnection"},"content":{"rendered":"<p><strong>SSH<\/strong>\u00a0or\u00a0<strong>Secure Shell<\/strong>\u00a0in simple terms is a way by which a person can remotely access another user on other system but only in command line i.e. non-GUI mode. In more technical terms, when we ssh on to other user on some other system and run commands on that machine, it actually creates a pseudo-terminal and attaches it to the login shell of the user logged in.<\/p>\n<div id=\"attachment_18908\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Keep-SSH-Sessions-Running.png\" rel=\"attachment wp-att-18908\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18908\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Keep-SSH-Sessions-Running.png\" alt=\"Keep SSH Sessions Running After Disconnection\" width=\"718\" height=\"345\" aria-describedby=\"caption-attachment-18908\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18908\" class=\"wp-caption-text\">5 Ways to Keep SSH Sessions Running After Disconnection<\/p>\n<\/div>\n<p>When we log out of the session or the session times out after being idle for quite some time, the\u00a0<strong>SIGHUP<\/strong>\u00a0signal is send to the pseudo-terminal and all the jobs that have been run on that terminal, even the jobs that have their parent jobs being initiated on the pseudo-terminal are also sent the SIGHUP signal and are forced to terminate.<\/p>\n<p><b>Don\u2019t Miss:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/5-best-practices-to-secure-and-protect-ssh-server\/\" target=\"_blank\" rel=\"noopener\">5 Useful Practices to Keep SSH Server Secure and Protected<\/a><\/p>\n<p>Only the jobs that have been configured to ignore this signal are the ones that survive the session termination. On Linux systems, we can have many ways to make these jobs running on the remote server or any machine even after user logout and session termination.<\/p>\n<h3>Understand Processes on Linux<\/h3>\n<h4>Normal Process<\/h4>\n<p>Normal processes are those which have life span of a session. They are started during the session as foreground processes and end up in certain time span or when the session gets logged out. These processes have their owner as any of the valid user of the system, including root.<\/p>\n<h4>Orphan Process<\/h4>\n<p>Orphan processes are those which initially had a parent which created the process but after some time, the parent process unintentionally died or crashed, making init to be the parent of that process. Such processes have init as their immediate parent which waits on these processes until they die or end up.<\/p>\n<h4>Daemon Process<\/h4>\n<p>These are some intentionally orphaned processes, such processes which are intentionally left running on the system are termed as daemon or intentionally orphaned processes. They are usually long-running processes which are once initiated and then detached from any controlling terminal so that they can run in background till they do not get completed, or end up throwing an error. Parent of such processes intentionally dies making child execute in background.<\/p>\n<h3>Techniques to Keep SSH Session Running After Disconnection<\/h3>\n<p>There can be various ways to leave ssh sessions running after disconnection as described below:<\/p>\n<h4>1. Using screen Command to Keep SSH Sessions Running<\/h4>\n<p><strong>screen<\/strong>\u00a0is a text Window Manager for Linux which allows user to manage multiple terminal sessions at same time, switching between sessions, session logging for the running sessions on screen, and even resuming the session at any time we desire without worrying about the session being logged out or terminal being closed.<\/p>\n<p>screen sessions can be started and then detached from the controlling terminal leaving them running in background and then be resumed at any time and even at any place. Just you need to start your session on the screen and when you want, detach it from pseudo-terminal (or the controlling terminal) and logout. When you feel, you can re-login and resume the session.<\/p>\n<h5>Starting a screen Session<\/h5>\n<p>After typing\u00a0<strong>\u2018screen\u2019<\/strong>\u00a0command, you will be in a new screen session, within this session you can create new windows, traverse between windows, lock the screen, and do many more stuff which you can do on a normal terminal.<\/p>\n<pre>$ screen\r\n<\/pre>\n<div id=\"attachment_18889\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Starting-Screen-Session-in-Linux.png\" rel=\"attachment wp-att-18889\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18889\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Starting-Screen-Session-in-Linux.png\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Starting-Screen-Session-in-Linux.png 915w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Starting-Screen-Session-in-Linux-768x416.png 768w\" alt=\"Starting Screen Session in Linux\" width=\"915\" height=\"496\" aria-describedby=\"caption-attachment-18889\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18889\" class=\"wp-caption-text\">Starting Screen Session in Linux<\/p>\n<\/div>\n<p>Once screen session started, you can run any command and keep the session running by detaching the session.<\/p>\n<div id=\"attachment_18890\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Commands-in-Screen-Session.png\" rel=\"attachment wp-att-18890\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18890\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Commands-in-Screen-Session.png\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Commands-in-Screen-Session.png 915w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Commands-in-Screen-Session-768x416.png 768w\" alt=\"Run Commands in Screen Session\" width=\"915\" height=\"496\" aria-describedby=\"caption-attachment-18890\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18890\" class=\"wp-caption-text\">Run Commands in Screen Session<\/p>\n<\/div>\n<h5>Detaching a Screen<\/h5>\n<p>Just when you want to log out of the remote session, but you want to keep the session you created on that machine alive, then just what you need to do is detach the screen from the terminal so that it has no controlling terminal left. After doing this, you can safely logout.<\/p>\n<p>To detach a screen from the remote terminal, just press\u00a0<code>\u201cCtrl+a\u201d<\/code>\u00a0immediately followed by\u00a0<code>\u201cd\u201d<\/code>\u00a0and you will be back to the terminal seeing the message that the Screen is detached. Now you can safely logout and your session will be left alive.<\/p>\n<div id=\"attachment_18891\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Detaching-Linux-Screen-Session.png\" rel=\"attachment wp-att-18891\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18891\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Detaching-Linux-Screen-Session.png\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Detaching-Linux-Screen-Session.png 915w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Detaching-Linux-Screen-Session-768x416.png 768w\" alt=\"Detaching Linux Screen Session\" width=\"915\" height=\"496\" aria-describedby=\"caption-attachment-18891\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18891\" class=\"wp-caption-text\">Detaching Linux Screen Session<\/p>\n<\/div>\n<h5>Resuming Detached Screen Session<\/h5>\n<p>If you want to Resume a detached screen session which you left before logging out, just re-login to remote terminal again and type\u00a0<code>\u201cscreen -r\u201d<\/code>\u00a0in case if only one screen is opened, and if multiple screen sessions are opened run\u00a0<code>\u201cscreen -r &lt;pid.tty.host&gt;\u201d<\/code>.<\/p>\n<pre>$ screen -r\r\n$ screen -r &lt;pid.tty.host&gt;\r\n<\/pre>\n<div id=\"attachment_18893\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Resume-Deatched-Screen-Session.png\" rel=\"attachment wp-att-18893\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18893\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Resume-Deatched-Screen-Session.png\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Resume-Deatched-Screen-Session.png 915w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Resume-Deatched-Screen-Session-768x416.png 768w\" alt=\"Resume Detached Screen Session\" width=\"915\" height=\"496\" aria-describedby=\"caption-attachment-18893\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18893\" class=\"wp-caption-text\">Resume Detached Screen Session<\/p>\n<\/div>\n<p>To Learn more about screen command and how to use it just follow the link:\u00a0<a href=\"https:\/\/www.tecmint.com\/screen-command-examples-to-manage-linux-terminals\/\" target=\"_blank\" rel=\"noopener\">Use screen Command to Manage Linux Terminal Sessions<\/a><\/p>\n<h4>2. Using Tmux (Terminal Multiplexer) to Keep SSH Sessions Running<\/h4>\n<p><strong>Tmux<\/strong>\u00a0is another software which is created to be a replacement for\u00a0<strong>screen<\/strong>. It has most of the capabilities of\u00a0<strong>screen<\/strong>, with few additional capabilities which make it more powerful than screen.<\/p>\n<p>It allows, apart from all options offered by screen, splitting panes horizontally or vertically between multiple windows, resizing window panes, session activity monitoring, scripting using command line mode etc. Due to these features of tmux, it has been enjoying wide adoption by nearly all Unix distributions and even it has been included in the base system of OpenBSD.<\/p>\n<h5>Start a Tmux Session<\/h5>\n<p>After doing ssh on the remote host and typing\u00a0<strong>tmux<\/strong>, you will enter into a new session with a new window opening in front of you, wherein you can do anything you do on a normal terminal.<\/p>\n<pre>$ tmux\r\n<\/pre>\n<div id=\"attachment_18895\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Start-tmux-Terminal-Session.png\" rel=\"attachment wp-att-18895\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18895\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Start-tmux-Terminal-Session.png\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Start-tmux-Terminal-Session.png 915w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Start-tmux-Terminal-Session-768x416.png 768w\" alt=\"Start tmux Terminal Session\" width=\"915\" height=\"496\" aria-describedby=\"caption-attachment-18895\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18895\" class=\"wp-caption-text\">Start tmux Terminal Session<\/p>\n<\/div>\n<p>After performing your operations on the terminal, you can detach that session from the controlling terminal so that it goes into background and you can safely logout.<\/p>\n<div id=\"attachment_18896\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Perform-Linux-Commands.png\" rel=\"attachment wp-att-18896\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18896\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Perform-Linux-Commands.png\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Perform-Linux-Commands.png 915w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Perform-Linux-Commands-768x416.png 768w\" alt=\"Perform Linux Commands in Tmux Session\" width=\"915\" height=\"496\" aria-describedby=\"caption-attachment-18896\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18896\" class=\"wp-caption-text\">Perform Linux Commands in Tmux Session<\/p>\n<\/div>\n<h5>Detach Tmux Session from Terminal<\/h5>\n<p>Either you can run\u00a0<code>\u201ctmux detach\u201d<\/code>\u00a0on running tmux session or you can use the shortcut\u00a0<code>(Ctrl+b then d)<\/code>. After this your current session will be detached and you will come back to your terminal from where you can log out safely.<\/p>\n<pre>$ tmux detach\r\n<\/pre>\n<div id=\"attachment_18897\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Detach-Tmux-Session-in-Linux.png\" rel=\"attachment wp-att-18897\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18897\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Detach-Tmux-Session-in-Linux.png\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Detach-Tmux-Session-in-Linux.png 915w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Detach-Tmux-Session-in-Linux-768x416.png 768w\" alt=\"Detach Tmux Session in Linux\" width=\"915\" height=\"496\" aria-describedby=\"caption-attachment-18897\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18897\" class=\"wp-caption-text\">Detach Tmux Session in Linux<\/p>\n<\/div>\n<h5>Resuming the Closed Tmux Session<\/h5>\n<p>To re-open the session which you detached and left as is when you logged out of the system, just re-login to the remote machine and type\u00a0<strong>\u201ctmux attach\u201d<\/strong>\u00a0to reattach to the closed session and it will be still be there and running.<\/p>\n<pre>$ tmux attach\r\n<\/pre>\n<div id=\"attachment_18898\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Resume-Tmux-Closed-Session.png\" rel=\"attachment wp-att-18898\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18898\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Resume-Tmux-Closed-Session.png\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Resume-Tmux-Closed-Session.png 915w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Resume-Tmux-Closed-Session-768x416.png 768w\" alt=\"Resume Tmux Closed Session\" width=\"915\" height=\"496\" aria-describedby=\"caption-attachment-18898\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18898\" class=\"wp-caption-text\">Resume Tmux Closed Session<\/p>\n<\/div>\n<p>To Learn more about tmux and how to use it just follow the link:\u00a0<a href=\"https:\/\/www.tecmint.com\/tmux-to-access-multiple-linux-terminals-inside-a-single-console\/\" target=\"_blank\" rel=\"noopener\">Use Tmux Terminal Multiplexer to Manage Multiple Linux Terminals<\/a>.<\/p>\n<h4>3. Using nohup command to Keep Running SSH Sessions<\/h4>\n<p>If you are not that familiar with\u00a0<strong>screen<\/strong>\u00a0or\u00a0<strong>tmux<\/strong>, you can use\u00a0<strong>nohup<\/strong>\u00a0and send your long running command to background so that you can continue while the command will keep on executing in background. After that you can safely log out.<\/p>\n<p>With nohup command we tell the process to ignore the\u00a0<strong>SIGHUP<\/strong>\u00a0signal which is sent by ssh session on termination, thus making the command persist even after session logout. On session logout the command is detched from controlling terminal and keeps on running in background as daemon process.<\/p>\n<h5>Executing command using nohup in background<\/h5>\n<p>Here, is a simple scenario wherein, we have run\u00a0<a href=\"https:\/\/www.tecmint.com\/35-practical-examples-of-linux-find-command\/\" target=\"_blank\" rel=\"noopener\">find command to search for files<\/a>\u00a0in background on ssh session using nohup, after which the task was sent to background with prompt returning immediately giving\u00a0<strong>PID<\/strong>\u00a0and job\u00a0<strong>ID<\/strong>\u00a0of the process\u00a0<code>([JOBID] PID)<\/code>.<\/p>\n<pre># nohup find \/ -type f $gt; files_in_system.out 2&gt;1 &amp;\r\n<\/pre>\n<div id=\"attachment_18899\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Command-in-Background.png\" rel=\"attachment wp-att-18899\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18899\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Command-in-Background.png\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Command-in-Background.png 915w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Command-in-Background-768x416.png 768w\" alt=\"Run Linux Command in Background\" width=\"915\" height=\"496\" aria-describedby=\"caption-attachment-18899\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18899\" class=\"wp-caption-text\">Run Linux Command in Background<\/p>\n<\/div>\n<h5>Resuming the session to view if job is still running<\/h5>\n<p>When you re-login again, you can check the status of command, bring it back to foreground using\u00a0<code>'fg %JOBID'<\/code>\u00a0to monitor its progress and so on. Below, the output shows that the job was completed as it doesn\u2019t show on re-login, and has given the output which is displayed.<\/p>\n<pre># fg %JOBID\r\n<\/pre>\n<div id=\"attachment_18899\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Command-in-Background.png\" rel=\"attachment wp-att-18899\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18899\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Command-in-Background.png\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Command-in-Background.png 915w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Command-in-Background-768x416.png 768w\" alt=\"Run Linux Command in Background\" width=\"915\" height=\"496\" aria-describedby=\"caption-attachment-18899\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18899\" class=\"wp-caption-text\">Run Linux Command in Background<\/p>\n<\/div>\n<h4>4. Using disown Command to Keep SSH Sessions Running<\/h4>\n<p>Another elegant way of letting your command or a single task run in background and remain alive even after session logout or disconnection is by using\u00a0<strong>disown<\/strong>.<\/p>\n<p><strong>Disown<\/strong>, removes the job from the process job list of the system, so the process is shielded from being killed during session disconnection as it won\u2019t receive\u00a0<strong>SIGHUP<\/strong>\u00a0by the shell when you logout.<\/p>\n<p>Disadvantage of this method is that, it should be used only for the jobs that do not need any input from the\u00a0<strong>stdin<\/strong>and neither need to write to\u00a0<strong>stdout<\/strong>, unless you specifically redirect jobs input and output, because when job will try to interact with\u00a0<strong>stdin<\/strong>\u00a0or\u00a0<strong>stdout<\/strong>, it will halt.<\/p>\n<h5>Executing command using disown in background<\/h5>\n<p>Below, we sent\u00a0<strong>ping<\/strong>\u00a0command to background so that ut keeps on running and gets removed from job list. As seen, the job was first suspended, after which it was still in the job list as\u00a0<strong>Process ID: 15368<\/strong>.<\/p>\n<pre>$ ping tecmint.com &gt; pingout &amp;\r\n$ jobs -l\r\n$ diswon -h %1\r\n$ ps -ef | grep ping\r\n<\/pre>\n<div id=\"attachment_18924\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Commands-Using-Disown.png\" rel=\"attachment wp-att-18924\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18924\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Commands-Using-Disown.png\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Commands-Using-Disown.png 915w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Commands-Using-Disown-768x416.png 768w\" alt=\"Run Linux Commands Using Disown\" width=\"915\" height=\"496\" aria-describedby=\"caption-attachment-18924\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18924\" class=\"wp-caption-text\">Run Linux Commands Using Disown<\/p>\n<\/div>\n<p>After that disown signal was passed to the job, and it was removed from job list, though was still running in background. The job would still be running when you would re-login to the remote server as seen below.<\/p>\n<pre>$ ps -ef | grep ping\r\n<\/pre>\n<div id=\"attachment_18925\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Verify-Job-Status.png\" rel=\"attachment wp-att-18925\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18925\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Verify-Job-Status.png\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Verify-Job-Status.png 915w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Verify-Job-Status-768x416.png 768w\" alt=\"Verify Job Status\" width=\"915\" height=\"496\" aria-describedby=\"caption-attachment-18925\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18925\" class=\"wp-caption-text\">Verify Job Status<\/p>\n<\/div>\n<h4>5. Using setsid Command to Put SSH Sessions Running<\/h4>\n<p>Another utility to achieve the required behavior is\u00a0<strong>setsid<\/strong>.\u00a0<strong>Nohup<\/strong>\u00a0has a disadvantage in the sense that the process group of the process remains the same so the process running with nohup is vulnerable to any signal sent to the whole process group (like\u00a0<code>Ctrl + C<\/code>).<\/p>\n<p><strong>setsid<\/strong>\u00a0on other hand allocates a new process group to the process being executed and hence, the process created is totally in a newly allocated process group and can execute safely without fear of being killed even after session logout.<\/p>\n<h5>Execute any command using setsid<\/h5>\n<p>Here, it shows that the process\u00a0<code>\u2018sleep 10m\u2019<\/code>\u00a0has been detached from the controlling terminal, since the time it has been created.<\/p>\n<pre>$ setsid sleep 10m\r\n$ ps -ef | grep sleep\r\n<\/pre>\n<div id=\"attachment_18903\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Command-Using-Setsid.png\" rel=\"attachment wp-att-18903\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18903\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Command-Using-Setsid.png\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Command-Using-Setsid.png 915w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Linux-Command-Using-Setsid-768x416.png 768w\" alt=\"Run Linux Command Using Setsid\" width=\"915\" height=\"496\" aria-describedby=\"caption-attachment-18903\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18903\" class=\"wp-caption-text\">Run Linux Command Using Setsid<\/p>\n<\/div>\n<p>Now, when you would re-login the session, you will still find this process running.<\/p>\n<pre>$ ps -ef | grep [s]leep\r\n<\/pre>\n<div id=\"attachment_18904\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Linux-Process-Running-Background.png\" rel=\"attachment wp-att-18904\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18904\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Linux-Process-Running-Background.png\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Linux-Process-Running-Background.png 915w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Linux-Process-Running-Background-768x416.png 768w\" alt=\"Linux Process Running Background\" width=\"915\" height=\"496\" aria-describedby=\"caption-attachment-18904\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-18904\" class=\"wp-caption-text\">Linux Process Running Background<\/p>\n<\/div>\n<h3>Conclusion<\/h3>\n<p>What ways you could think of to keep your process running even after you logout from SSH session? If there is any other and efficient way you can think of, do mention in your comments.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/keep-remote-ssh-sessions-running-after-disconnection\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SSH\u00a0or\u00a0Secure Shell\u00a0in simple terms is a way by which a person can remotely access another user on other system but only in command line i.e. non-GUI mode. In more technical terms, when we ssh on to other user on some other system and run commands on that machine, it actually creates a pseudo-terminal and attaches &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/5-ways-to-keep-remote-ssh-sessions-and-processes-running-after-disconnection\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;5 Ways to Keep Remote SSH Sessions and Processes Running After Disconnection&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13268","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13268"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13268\/revisions"}],"predecessor-version":[{"id":13269,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13268\/revisions\/13269"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}