In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how the background process of Linux management is, and the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Preface
Do you often need SSH or telent to log in to the Linux server remotely? Do you often have headaches for long-running tasks, such as system backup, ftp transfer, and usual server compilation, etc. Usually we open a remote terminal window for each of these tasks because they take too long to execute. You must wait for it to finish, and during this time, you can't close the window or disconnect, otherwise the task will be killed and everything will be given up halfway.
Is there a window manager that reuses physical terminals between multiple processes (usually interactive shell), when the window is currently invisible, even when the entire screen session is offline from the user terminal, the program continues to run, and when it comes back, it continues to run and logs such as history?
Reason
Let's see why closing the window / disconnecting will kill the running program. 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, that is, the ID of the process leader process.
Session period (session): a collection of one or more process groups with a unique session header process (session leader). The ID of the process led by ID during the session.
There can be a separate control terminal (controlling terminal) during the session. The first session process connected to the control terminal is called the control process (controlling process). The process currently interacting with the terminal is called the foreground process group. The rest of the process groups are called background process groups.
According to the definition of POSIX.1. 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 sends a hang-up signal to the control process (the first process of the session). If the first process of the session terminates, the signal is sent to the foreground process group of the session. When a process exits and results in an orphan process group being generated, if any of the orphan process group processes are in STOP state, send SIGHUP and SIGCONT signals to all processes in the process group.
Therefore, when the network is disconnected or the terminal window is closed, the control process receives the SIGHUP signal to exit, which will cause other processes to exit during the session period.
If we can ignore the SIGHUP signal, closing the window should not affect the running of the program. The nohup command does this, and if the standard output / standard error of the program is terminal, nohup redirects it to the nohup.out file by default. It is worth noting that the nohup command only causes the program to ignore the SIGHUP signal and also needs to use a tag & to run it in the background.
Although nohup is easy to use, it is still "crude". It is troublesome to be able to cope with simple commands and complex tasks that require human-computer interaction.
We could actually use a more powerful utility, screen. Popular Linux distributions, such as Red Hat Enterprise Linux 4, usually come with the screen utility, which, if not available, can be downloaded from GNU screen's official website.
Http://www.gnu.org/software/screen/
How to use
To put it simply, Screen is a window manager that can multiplex a physical terminal between multiple processes. There is the concept of session in Screen, where users can create multiple screen windows in a screen session, each screen window as if it were a real telnet/SSH connection window. There are two ways to create a new window in screen.
Before you start using screen, you need to make sure that the terminal type is selected correctly, just as with any other termcap / terminfo program. Then type screen to start a new process. Type exit to exit the background.
Adding screen to the command also creates a single-window session.
There are also some common commands to see which background processes are available.
Screen-ls
Restore a process id
Screen-r screen_id
There are also some advanced uses, such as creating a process name, setting a title, and wipe dropping processes that have been removed. Linux also has a similar command tmux, which you can use to Google yourself. Use it. Use it all the time.
On the Linux management background process is how 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.