In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
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.
Summary
The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support. If you want to know more about it, please see the relevant links below.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.