Labels

Android (1) bash (2) boost (2) C (34) C++ (2) cheatsheet (2) CLion (6) css (3) Debian (33) DL (17) Docker (1) Dreamweaver (2) Eclipse (3) fail2ban (4) git (5) GitHub (4) Hacking (3) html (8) http (1) iOS (1) iPad (1) IRC (1) Java (30) javascript (3) Linux (164) Mac (19) Machine Learning (1) mySQL (47) Netbeans (4) Networking (1) Nexus (1) OpenVMS (6) Oracle (1) Pandas (3) php (16) Postgresql (8) Python (9) raid (1) RedHat (14) Samba (2) Slackware (45) SQL (14) svn (1) tar (1) ThinkPad (1) Virtualbox (3) Visual Basic (1) Visual Studio (1) Windows (2)

Monday 21 December 2020

Put processes into the background

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.