Permission denied when Starting Screen

When you are starting screen, and you are unable to create a screen session, and you have errors like

user1@node1 ~]$ screen
You are not the owner of /var/run/screen/S-user1

Check the permission of /var/run/screen/S-user1 to make sure you own the directory

$ chown user1:user1 /var/run/screen/S-user1

Running process in the background

I have just started another blog to deal with more specific topics on Linux. Finally wrote one…… It is Running process in the background. The blog mentions 3 tools

Solution 1: Nohup and ampersand

$ myscript.sh &

The ampersand “&” tells the shell to run the script in the background. You will get the prompt back. But as the script is still a child of the shell. In other words, if you terminate the shell, the script will terminate as well.

To overcome this you may want to use the command “nohup” which ignore the HUP Termination signals. The output will be sent to the “nohup.out” in the current directory

$ nohup myscript.sh &

Alternatively, you may want to redirect to the standard output to standard error to /dev/null

$ nohub myscript.sh  > /dev/null 2>&1 &

Solution 2: Screen

There is a post written by me on Basic GNU Screen Usage on CentOS which you might want to read for more information.

You may want to use screen to run a shell. You may want to name a screen session

$ screen -S my_preferred_screen_name -m

You can also list running Screen Session

$ screen -ls
There is a screen on:
2109.myScreenA (Detached)
1 Socket in /var/run/screen/S-user1

To reattach the Screen Session

screen -r 2109

To detach from a screen session. [Press ctrl with “a” and “d” together]

Ctrl-a + d

Solution 3: tmux

If you prefer to use tmux. You may want to take a look at A beginner’s guide to tmux for more information. If you are starting a session

$ tmux new ./myscript.sh

If you are detaching a session

$ tmux new -d ./myscript.sh

Basic GNU Screen Usage on CentOS

Introduction

Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells. In other words, you can start any number of virtual terminals inside the session. The good thing is that processes running inside screen will continue to run even though the SSH session get disconnected.

GNU Screen Site

GNU Screen can be found on http://ftp.gnu.org/gnu/screen/

Source Code

You can get the source code from here

Using Screen

Screen can be easily installed on CentOS with just

# yum install screen

Naming a Named Session

You may be running many sessions and it is a good idea to name the session that you are starting.

screen -S your_preferred_screen_name

Listing running Screen Session

[user1@node1 ~]$ screen -ls
There is a screen on:
2109.myScreenA (Detached)
1 Socket in /var/run/screen/S-user1

Reattach to a Screen Session

To connect back to the screen, just type the numeric id of the screen

screen -r 2109

Detaching from a Screen Session

Inside the Virtual Session, you can detach the screen with the command

Ctrl-a + d

[Press ctrl with “a” and “d” together]
If you are already outside the virtual session, you can detach an active session by

screen -d 2109

Customised Screen

If you a looking at how to split Screen using screen. Here is a good visual guide.

To Terminate the Screen Session,

Enter into the Session screen

screen -r 2109
exit

 

User Guide

https://www.gnu.org/software/screen/manual/screen.html#Startup-Files

Links:

How To Use Linux Screen