In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to run the Linux command in the background and detach the process from the terminal". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to run the Linux command in the background and detach the process from the terminal.
In this guide, we will clarify a simple but important concept of process management in Linux systems, that is, how to completely detach a process from its control terminal.
When a process is associated with a terminal, two problems may occur:
Your control terminal is full of output data or errors and diagnostic information.
If a terminal shutdown occurs, the process and its child processes will be terminated
To solve the above two problems, you need to be completely detached from a process from a control terminal. Before we actually solve this problem, let's briefly introduce how to run a process in the background.
How to start a Linux process or command line in the background
If a process is already running, such as the following example on the tar command line, simply press Ctrl+Z to stop it, and then type the command bg to continue to run as a task in the background.
You can view all background tasks by typing jobs. However, standard input (STDIN), standard output (STDOUT), and standard error (STDERR) are still mixed into the console.
$tar-czf home.tar.gz. $bg $jobs
Run the Linux command in the background
You can also use symbols directly & to run a process in the background:
$tar-czf home.tar.gz. & $jobs
Start a Linux process in the background
Take a look at the following example. Although the tar command starts as a background task, the error message is still sent to the terminal, indicating that the process is still associated with the control terminal.
$tar-czf home.tar.gz. & $jobs
Linux process information running in the background
After exiting the console, keep the Linux process running
We will use the disown command, which is used after a process is already running and is placed in the background, and its function is to remove a shell task from the active task list of shell, so you will no longer be able to use the fg, bg commands for that task.
Also, when you close the control terminal, the task will not be suspended (paused) or send SIGHUP signals to any of the subtasks.
Let's take a look at the following example of using the built-in command disown in bash.
$sudo rsync Templates/* / var/www/html/files/ & $jobs $disown-h% 1$ jobs
After closing the terminal, keep the Linux process running
You can also use the nohup command, which also ensures that the process continues to run in the background after the user exits shell.
$nohup tar-czf iso.tar.gz Templates/* & $jobs
Put the Linux process in the background after closing shell
Detach a Linux process from the control terminal
Therefore, in order to completely detach a program from the control terminal, it is more efficient for graphical user interface (GUI) programs such as firefox to use the following command line format:
$firefox / dev/null &
On Linux, / dev/null is a special file device that ignores all data written on it. The above command, input source and output are all sent to / dev/null.
As a closing statement, run a process connected to the control terminal, and as a user you will see the output of many lines of process data on your terminal, with error messages. Similarly, when you close a control terminal, both your processes and child processes will be terminated.
At this point, I believe you have a deeper understanding of "how to run the Linux command in the background and detach the process from the terminal". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.