If we're doing something when logged in to a terminal and we are disconnected, typically whatever we were doing is interrupted and generally this isn't a good thing.
Naturally, we can always send a process into the background by adding the & but there are situations where this might not be exactly what we want to do, given that if we are logged in remotely and are disconnected, then so is the process.
What we can do instead, is use screen
Basically, once screen is installed and we're logged in, do;
screen
then start whatever it is we wish to do, be it a long process or a lengthy download and then do;
CTRL + a (and then d)
Keep CTRL pressed, then press a and then d
This detaches from the screen session, we can then close the session or whatever and when we wish to return at a later date, we simply run screen -r which should resume the previous session. If there are more than one previous session, they will be listed, along with instructions on how to return to each detached screen, generally screen -r pid
If we wish to exist the screen session, we simply use exit
If screen isn't installed then we can of course resort to running the command with the & afterwords as mentioned above or alternatively, we can also use CTRL + z which will pause the process and then we can type bg to put it into the backround.
We can show all jobs running in the background with the jobs command.
fg will put a process into the foreground, if we do fg alone, it will bring the last process into the foreground. If there is more than 1 process in the background as shown by the jobs command, then fg n will bring that specific process into the foreground.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.