ProgrammeBeimLogoutNichtBeenden

Last modified by Aysegül Omus on 2026/05/13 15:53

How to run programs in a way that they don’t terminate when you log out

Here is how you can still run programs after logging out. This happens by starting the programs on the server, which is configured identically on the computers in the hall.

1. General information

If a student wants to run a computer-intensive program at night, this is, in principle, not a problem, as long as the following points are taken into consideration:

 To connect to lxhalle via SSH, you have to enter the passphrase in the terminal below your cit. tum-Login (CIT-Login). Here is how to for Windows users: set up PuTTY, which enables SSH connections via the terminal. ssh CIT-Login@lxhalle.cit.tum.de

  • To prevent the programs from harming other computer users, they should be started with the lowest possible scheduling priority. This happens with the command \“nice -n19\” as shown in the HowTo example. 

2. Script example

To demonstrate the functionality of the presented methods, below is a small shell script, test.sh, that writes the current date to datum.txt every second. This is just an example of a program that can run in the console. The script is composed of the following line of code:

%CODE{ lang=\"bash\" }% #!/bin/bash while true do sleep 1 date done >> datum.txt

%ENDCODE%


3. nohup

If a program is started with the nohup command, the HUP signal sent by the logout is ignored. So the program proceeds further even after the user has already logged out

  • The following input nice -n 19 nohup ./test.sh & starts the test script, and the control operator (&) makes the command run in the background.
  • From now on, the date is written in the file datum.txt, and even after the user logs out
  • after running nohup, the PID of the process is shown. PID can be used to close a program (if it doesn’t terminate automatically). To do so, you should enter the following command: kill PID.
  • Now you can continue your work in the terminal, or you can close it without terminating the program
  • by logging out, and then once again in, you can check whether in the file datum.txt it’s still written
    https://xwiki.rbg.tum.de/bin/download/Informatik/Helpdesk/ProgrammeBeimLogoutNichtBeenden/WebHome/nohupTest.png

4. screen

The screen command enables you to create multiple screen sessions, each of which can consist of up to 10 virtual consoles. In this console, you can start programs that remain even after the session of the terminal window is closed.

 First, here are some basic control commands:

  • start screen:
    • nice -n 19 screen
    • command for starting a session with a customized name (in our case, named sitzung1) nice -n 19 screen -S sitzung1
  • At the beginning, some program information is displayed, and then you can press the space bar. The console will still remain unchanged – you have started the screen session and you are now in the first virtual console
  • start one more virtual console:
    • Strg + A and then C
  • close a virtual console:
    • Strg + A and then K
  • switch between the virtual consoles:
    • Strg + A and then Leertaste
    • Strg + A and then a number between 0 and 9 (for the corresponding console)
  • detach the current session:
    • Strg + A and then D
    • for a certain session (in this case, sitzung1) screen -d sitzung1
  • reestablish connection to a session (here sitzung1)
    • screen -r sitzung1
  • end session
    • Strg + D
    • exit
    • Close the last virtual console
  • List all running sessions with their names (example in picture is 6561) screen -ls
    https://xwiki.rbg.tum.de/bin/download/Informatik/Helpdesk/ProgrammeBeimLogoutNichtBeenden/WebHome/screen.jpg
  • show all keyboard shortcuts
    • Enter Strg + A and then?
  • Refer to the man pages for the full documentation of the screen command man screen

 Steps for using the screen (see the commands above):

  • start programs
    • Open a terminal window
    • start screen – thereby automatically creating a session that is attached
    • run program
    • start new consoles and programs if needed
    • detach the current sessions
    • close terminal window
  • end programs
    • Open a terminal window
    • List all running screen sessions
    • Resume desired screen sessions
    • end the programs in the virtual consoles (if they don’t terminate on their own)
    • Close the virtual console, respectively, close the session
    • close terminal window