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 > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "how to run the Python program in the Linux background". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to run the Python program in the Linux background" can help you solve your doubts.
1. The first method is to directly use the unhup command to make the program run in the background. The command format is as follows:
Unhup python file name.py (> * * .log) &
In this command, python specifies that the file we want to execute is the python file, followed by the file name .py. The parentheses indicate that the content normally output to the console can be redirected to the * .log file. This is optional. If this is not available, it will be output to the nohup.out file by default. Your & after the parentheses indicates running in the background.
two。 The second method is to write a script and then submit the script to the server and let the server run the statements in the script in the background. Suppose we define a script start.sh that contains the following:
#! / bin/bashcd wants to run the file path name python-u * * .py
In the above script, #! / bin/bash means that the script uses / bin/bash to interpret and execute the following statement, where cd means to jump the current directory to the directory where you want to run the file, and then python-u * .py means to run the * python file. After writing the script, we can use the following command to execute the script so that the program runs in the background:
. / start.sh > result.log &
Here. / start.sh means to run the script start.sh in the current directory, > result.log means to output everything originally output to the console to the result.log file, and & means to run in the background
We can see which processes are running in the background through the ps-e command.
In the picture above, we can see that our scripts start.sh and python programs have been successfully run in the background, and then we can view the original output information to the console through cat result.log | more.
Note: if you want to execute a function in the python file, you must remember to call the function in the file in addition to defining the function.
After reading this, the article "how to run Python programs in the Linux background" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.
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.