Will my screen process continue after i log out?

5,047

Screen is meant to do exactly that. You can test this in advance by doing this:

$ sudo su -- # Note that you should use 2 dashes, here, if you use any (you don't have to, `sudo su` would do the same thing).
# screen
# # Press [enter].
# sleep 100 && echo foo
# # Press [ctrl]+[A], then [D].
# # Press [ctrl]+[D].
$ sudo su
# screen -r
# # You'll be shown the line you entered before, again. After some time (100 seconds after you entered the 4th line), "foo" will be printed.

All lines starting with $ are executed as a normal user. All lines starting with # are executed as root. # later in a line marks the beginning of a single-line comment.

In the first line, you log in as root. You should probably figure out whether it's necessary to run the Minecraft server as root.

In the second line, you enter screen.

Pressing enter is just to make the text screen shows you when you open it without parameters go away.

In the 4th line, a command symbolizing your Minecraft server is executed. It sleeps for 100 seconds and then prints "foo".

By pressing crtl+A and then D, you disconnect from the screen in the 5th line.

In the 6th line, you disconnect from the terminal session by pressing ctrl+D. Note that this leaves your terminal open as you are logged in as a regular user on a lower level. You only disconnect from the terminal session on the top level. Your logging out as root and may as well use exit to do this if it helps you to understand that you're really logging out. You can log out as the regular user, too. Just press ctrl+D, again. If this is the lowest level and you're on a tty, you'll be shown the login screen, again. If it's the lowest level and you're using a terminal emulator, the terminal window will close. There is absolutely no problem with this.

In the 7th line, you log in as root, again.

In the 8th line, the magic happens. You call screen with flag r which as taken from screen's man page (run man screen) means:

Reattach a session and if necessary detach it first.

Because you only have one session in screen, you get back to the right one.

After some time, "foo" will be printed on the screen which means that you'll see it on your terminal when you are connected to the screen or connect to it later. All your commands and their outputs will still be visible. Execution happens while you're not necessarily logged in.

Share:
5,047

Related videos on Youtube

tjespe
Author by

tjespe

Updated on September 18, 2022

Comments

  • tjespe
    tjespe about 1 year

    I opened a screen as root user by typing sudo su - and then screen. I then ran a command to start my Minecraft server.

    After that I detached the screen by pressing Ctrl-A and d. Will the process (my server) continue to run after I log out of my computer (without turning it off, obviously)?