In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use the nohup command in Linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
At this point we can use the command nohup.
The nohup command is an acronym for the English phrase no hangup, meaning not to hang up, that is, the program does not exit. This command causes the program to ignore the HUP signal and ensures that the program works properly. The HUP signal, which may be unfamiliar to some people, is a signal sent to the process associated with it when the terminal is aborted, and the process will stop running when it receives this signal. So if you don't want the process to be killed by this signal, you can ignore it. And that's what nohup commands to do.
In this article, we will describe the specific use of the nohup command in detail.
Basic syntax of nohup command
The basic syntax of the nohup command is as follows:
$nohup command arguments
Or:
$nohup options
If you want more information about the use of nohup, check out its help page:
$nohup-help
If you need to check its version number, you can use the-- version option.
$nohup-version
Start a program using the nohup command
If you need to run a program that keeps running even after the corresponding Shell is exited, you can run the program using nohup:
$nohup command
When the program starts, the corresponding log output of the program and its error log will be recorded in the nohup.out file, which is usually located in the home directory or the current directory.
The output of the redirector program
If I do not want to save the output of the program in the home directory or the current directory, I want to save it in the path I specified and customize the file name, what should I do? At this point, we can use the redirect operation.
For example, I now have a script myScript.sh that I want to save its output to the output directory in my home directory, with the file name myOutput.txt, which can be run like this:
$nohup. / myScript.sh > ~ / output/myOutput.txt
Use the nohup command to start a program in the background
If you want the program to run in the background, you can add the & symbol. But after running in this way, the program disappeared without a trace. To get the program back to the terminal, use the fg command.
The output log of this command will be saved in the nohup.out file, which you can view using cat or other commands. The number 8699 in the second line represents the process number corresponding to the command, that is, pid. We can use the ps command to find this process.
Running multiple programs at the same time using nohup
If you need to run multiple programs at the same time, you don't have to run them one by one, just use the & & symbol. For example, if you want to run mkdir and ping,ls commands at the same time, you can run them like this:
$nohup bash-c 'mkdir files & & ping-c 1 baidu.com & & ls' > output.txt
Stop the process running in the background
As mentioned above, the nohup command combined with the & symbol allows the process to run in the background, even if the terminal is closed. At this point, what do you do if you want to terminate the process?
The simplest is the kill command, which I believe you have used many times.
$kill-9 PID
So how do you find the corresponding pid for the process? We can use the ps command.
$ps aux | grep myScript.sh
Or you can use the pgrep command.
Next, use the kill command to terminate the process.
$kill-9 14942 Thank you for reading this article carefully. I hope the article "how to use nohup commands in Linux" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you 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.