How to Keep Remote SSH Sessions and Processes Running After Disconnection [nohup]
We can use nohup and send a long running command to background.
We can continue while the command will keep on executing in background.
After that We can safely log out.
With nohup command we tell the process to ignore the SIGHUP signal 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.
Here, is a simple scenario wherein,
we have run find command to search for files in background on ssh session using nohup,
after which the task was sent to background with prompt returning immediately giving PID and job ID of the process
Resuming the session to view if job is still running
When we re-login again,
we can check the status of command,
bring it back to foreground using 'fg jobID' to monitor its progress and so on.
Below, the output shows that the job was completed as it doesn’t show on re-login,
and has given the output which is displayed.
We can continue while the command will keep on executing in background.
After that We can safely log out.
With nohup command we tell the process to ignore the SIGHUP signal 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.
Here, is a simple scenario wherein,
we have run find command to search for files in background on ssh session using nohup,
after which the task was sent to background with prompt returning immediately giving PID and job ID of the process
# nohup find / -type f > files_in_system.out 2>&1 &
Resuming the session to view if job is still running
When we re-login again,
we can check the status of command,
bring it back to foreground using 'fg jobID' to monitor its progress and so on.
Below, the output shows that the job was completed as it doesn’t show on re-login,
and has given the output which is displayed.
# fg 1
Comments
Post a Comment