In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to use Screen to manage remote sessions. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
When developing locally, I often need to connect to the Linux server remotely. At the beginning, I always have several remote SSH windows open. This method is very primitive and straightforward, but I am fed up with password input every time. Even if I log in without a password with SSH, I will feel that the command to enter SSH is not fast at all, and if the windows are opened too much, it will be very confusing and difficult to manage. There are also many tools on Linux, so let's learn about screen tools today.
When introducing the screen tool, let's first discuss why the task is killed when we close the remote connection window when we perform a long-term task after connecting to the server.
Culprit: SIGUP signal
In Linux/Unix, there are several concepts:
Process group (process group): a collection of one or more processes, each with a unique process group ID
Session period (session): a collection of one or more process groups with a unique session header process (session leader) and a session period led by the ID process ID
During the session, there can be a single session terminal. The first process of the session connected with the control terminal is called the control process (controlling process). The process currently interacting with the terminal is called the foreground process group, and the rest of the process group is called the background process group.
Tool POSIX.1 definition:
The default action of hang up signal (SIGHUP) is to terminate the program.
When the terminal interface detects that the network connection is disconnected, it will send a SIGHUP signal to the control process (session first process)
If the first process of the session terminates, the signal is sent to the foreground process group for that session
When a process exits and causes an orphan process group to be generated, if a person an orphan process group process is in STOP state, SIGHUP and SIGCONT signals are sent to all processes in the process group.
Therefore, when the network is disconnected or the window is closed, the control process receives the SIGHUP signal to exit, which will cause other processes to exit during the session period.
A simple example
Open two SSH terminal windows and execute the ping command in the first:
In another terminal window, the ID of the process that finds ping is 22132, and its parent process ID is 21803, that is, log in to zsh:
Using ps-xj, you can see that the login zsh (PID 21803) and ping are in the same session period, and zsh is the first process of the session, so the process group in which the process group PGID is 21803 is 22132, which is the foreground process group.
At this point, we close the first SSH remote window and see that the ping process is killed in another window:
It is found that when we perform a time-consuming task, if we close the window, the task process is killed and does not continue to execute in the background as we expected.
Use screen
Now, there is no need to say much about what screen does, just say how to use it.
1. Execute the screen command directly
Screen will create a full-screen window to execute shell, and you can see that the title of the window has been prompted to be in the screen program, in which you can execute the command freely, if you want to exit, enter the exit command.
2. If you want to open a new window to perform another task, you can perform:
/ / method 1 Press the keyboard Ctrl+a + c to open a screen window / / the command of the task that the 2screen needs to perform, such as: screen ping www.baidu.com
3. Switch between multiple screen windows
Method 1 keyboard Ctrl+a + [0.. 9] method 2 keyboard Ctrl+a + n, next screen window keyboard Ctrl+a + p, last screen window
For more commands, see the following figure:
Screen is a window manager that can multiplex a physical terminal between multiple processes. There is also the concept of session in Screen. Users can create multiple screen windows in a screen session, and each screen window is like operating a real SSH connection window.
On the use of Screen to manage remote sessions to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.