Wiki source code of Programme so ausführen, dass sie beim Logout nicht beendet werden
Last modified by Yunhao Wu on 2023/07/05 16:11
Hide last authors
author | version | line-number | content |
---|---|---|---|
![]() |
11.2 | 1 | = How to run programs in a way, that they don’t terminate when you log out = |
![]() |
1.1 | 2 | |
![]() |
11.2 | 3 | Here is a description how you can still run programs after you have logged out. This happens by starting the programs on the server which is configured identically on the computers in the hall. |
![]() |
1.1 | 4 | |
5 | |||
6 | |||
7 | {{toc/}} | ||
8 | |||
9 | |||
10 | |||
![]() |
11.2 | 11 | == 1. General information == |
![]() |
1.1 | 12 | |
![]() |
11.2 | 13 | If a student wants to run a computer intensive program at night, this is in principle not a problem, as far as the following points are taken into consideration: |
![]() |
1.1 | 14 | |
![]() |
11.2 | 15 | in order to connect to lxhalle via SSH you have to enter in the terminal the passphrase, that is standing below your cit.tum-Login (CIT/ITO-Login). [[Here>>https://xwiki.rbg.tum.de/bin/view/Informatik/Helpdesk/Ssh_mit_PuTTY]] is !HowTo for Windows users, who should set up !PuTTY, which enables the ssh connection via terminal. {{{ssh ITO-Kennung@lxhalle.in.tum.de}}} |
![]() |
1.1 | 16 | |
![]() |
11.2 | 17 | * in order the programs to work without harming other computer users, they should be started with one of the lowest possible scheduling priorities. This happens with the command \“nice -n19\” as shown in the HowTo example. |
![]() |
8.1 | 18 | |
![]() |
1.1 | 19 | {{html wiki="true"}} |
20 | <hr /> | ||
21 | {{/html}} | ||
22 | |||
23 | |||
![]() |
11.2 | 24 | == 2. Script example == |
![]() |
1.1 | 25 | |
![]() |
11.2 | 26 | In order to demonstrate the functionality of the presented methods, below there is a small Shell-Script ##test.sh##, that writes every single second the actual date in ##datum.txt##. This is just an example of a program, that can run in the console. The script is composed by the following line of code: |
![]() |
1.1 | 27 | |
![]() |
11.2 | 28 | %CODE{ lang=\"bash\" }% #!/bin/bash while true do sleep 1 date done >> datum.txt |
![]() |
8.1 | 29 | |
![]() |
11.2 | 30 | %ENDCODE% |
31 | |||
![]() |
1.1 | 32 | ---- |
33 | |||
![]() |
8.1 | 34 | {{id name="NohupAnchor"/}} |
35 | |||
![]() |
1.1 | 36 | == 3. nohup == |
37 | |||
![]() |
11.2 | 38 | In case a program is started with the nohup command, the HUP-signal, that is send by the logout is ignored. So the program proceeds further even after the user has already logged out |
![]() |
8.1 | 39 | |
![]() |
11.2 | 40 | * the following input {{{nice -n 19 nohup ./test.sh & }}}starts the test script and the control operator (##&##) makes the command run in the background. |
41 | * from now on the date is written in the file ##datum.txt##, even after the user logs out | ||
42 | * 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##. | ||
43 | * now you can continue your work in the terminal or you can close it without terminating the program | ||
44 | * by logging out and then once again in, you can check, whether in the file ##datum.txt## it’s still written | ||
45 | [[image:https://xwiki.rbg.tum.de/bin/download/Informatik/Helpdesk/ProgrammeBeimLogoutNichtBeenden/WebHome/nohupTest.png]] | ||
![]() |
8.1 | 46 | |
![]() |
1.1 | 47 | ---- |
48 | |||
49 | == 4. screen == | ||
50 | |||
![]() |
11.2 | 51 | The screen command enables you to create more than one screen sessions, which once again can consist of up to 10 virtual consoles. In this consoles you can start programs, that remain even after the session of the terminal window is closed. |
![]() |
1.1 | 52 | |
53 | |||
![]() |
11.2 | 54 | First here are some basic control commands: |
![]() |
8.1 | 55 | |
![]() |
11.2 | 56 | * start screen: |
57 | ** {{{nice -n 19 screen}}} | ||
58 | ** command for starting a session with customized name (in our case named sitzung1) {{{nice -n 19 screen -S sitzung1}}} | ||
59 | * at the beginning some information for the program is shown and then you can click the space bar, the console will still remain unchanged – you have started the screen session and you are now in the first virtual console | ||
60 | * start one more virtual console: | ||
61 | ** ##Strg## + ##A## and then ##C## | ||
62 | * close a virtual console: | ||
63 | ** ##Strg## + ##A## and then ##K## | ||
64 | * switch between the virtual consoles: | ||
65 | ** ##Strg## + ##A## and then ##Leertaste## | ||
66 | ** ##Strg## + ##A## and then number between 0 and 9 (for the corresponding console) | ||
67 | * detach the current session: | ||
68 | ** ##Strg## + ##A## and then ##D## | ||
69 | ** for a certain session (in this case sitzung1) {{{screen -d sitzung1}}} | ||
70 | * reestablish connection to a session (here sitzung1) | ||
71 | ** screen -r sitzung1 | ||
72 | * end session | ||
![]() |
1.1 | 73 | ** ##Strg## + ##D## |
![]() |
11.2 | 74 | ** {{{exit}}} |
75 | ** close the last virtual console | ||
76 | * list all running session with their names (example in picture be 6561) {{{screen -ls }}} | ||
77 | [[image:https://xwiki.rbg.tum.de/bin/download/Informatik/Helpdesk/ProgrammeBeimLogoutNichtBeenden/WebHome/screen.jpg]] | ||
78 | * show all keyboard shortcuts | ||
79 | ** enter ##Strg## + ##A## and then ##?## | ||
80 | * refer to the man pages for the full documentation of the screen command {{{man screen}}} | ||
![]() |
1.1 | 81 | |
![]() |
11.2 | 82 | Steps for using the screen (see the commands above): |
![]() |
1.1 | 83 | |
![]() |
11.2 | 84 | * start programs |
85 | ** open terminal window | ||
86 | ** start screen – thereby automatically creating a session, that is attached | ||
87 | ** run program | ||
88 | ** start new consoles and programs if needed | ||
89 | ** detach the current sessions | ||
90 | ** close terminal window | ||
91 | * end programs | ||
92 | ** open terminal window | ||
93 | ** list all running screen sessions | ||
94 | ** resume desired screen sessions | ||
95 | ** end the programs in the virtual consoles (if they don’t terminate on their own) | ||
96 | ** close the virtual console respectively close the session | ||
97 | ** close terminal window | ||
![]() |
1.1 | 98 | |
99 | {{html wiki="true"}} | ||
100 | <hr /> | ||
101 | {{/html}} |