In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you about linux background execution commands-what's the use of nohup? I hope you will get something after reading this article. Let's discuss it together.
When we are working on a terminal or console, we may not want to occupy the screen by running a job, because there may be more important things to do, such as reading email. For processes with intensive access to disks, we prefer it to run during non-load peak hours of the day (for example, in the early hours of the morning). To enable these processes to run in the background, that is, not on the terminal screen, there are several options available.
&
When running a job in the foreground, the terminal is occupied by the job; you can add & to the command to run in the background. For example: sh test.sh &
Commands suitable for running in the background are f i n d, time-consuming sorting, and some s h e l l scripts. Be careful when running jobs in the background: commands that require user interaction should not be executed in the background, because your machine will be waiting there. However, running the job in the background will also output the results to the screen, interfering with your work. If a job running in the background produces a large amount of output, it is best to redirect its output to a file using the following method:
Command > out.file 2 > & 1 &
In this way, all standard output and error output will be redirected to a file called out.file.
PS: when you successfully submit a process, it will display a process number that you can use to monitor the process or kill it. (ps-ef | grep process number or kill-9 process number)
Nohup
After using the & command, the job is submitted to the background to run, and the current console is not occupied, but as soon as the current console is closed (when you exit the account), the job stops running. The nohup command allows you to continue running the process after you log out of your account. Nohup means not to hang (no hang up). The general form of the command is:
Nohup command &
If you submit a job using the nohup command, by default all output from the job is redirected to a file named nohup.out, unless another output file is specified:
Nohup command > myout.file 2 > & 1 &
After using nohup, many people just ignore it, in fact, it is possible that when the current account abnormally exits or ends, the order will end on its own. So after using the nohup command to run the command in the background, you need to use exit to exit the current account normally to ensure that the command runs in the background all the time.
Ctrl + z
You can put a command being executed in the foreground in the background and in a paused state.
Ctrl+c
Terminate the front desk order.
Jobs
See how many commands are currently running in the background.
The jobs-l option shows that the PID,jobs status of all tasks can be running, stopped, Terminated. But if the task is terminated (kill), shell removes the process identity of the task from the list known to the current shell environment.
2 > & 1 parsing
Command > out.file 2 > & 1 &
Command > out.file redirects the output of command to the out.file file, that is, the output is not printed to the screen, but to the out.file file.
2 > & 1 redirects the standard error to the standard output, where the standard output has been redirected to the out.file file, that is, the standard error is also output to the out.file file. The last & is to let the command be executed in the background.
Imagine what 2 > 1 stands for, 2 and > represents error redirection, while 1 represents error redirection to a file 1, not standard output; replace it with 2 > & 1, which represents standard output, and becomes an error redirection to standard output.
After reading this article, I believe you have a certain understanding of "linux background execution commands & what is the use of nohup". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!
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.