Example: We use the Python code loop_hello.py as an example. The code outputs the number of loops and hello world! in a loop, and sleeps for 1 second after each output. The sample code is as follows: import time def main(): i = 0 while True: i += 1 print('%d: hello world!' %(i)) time.sleep(1) if '__main__' == __name__: main() Run loop_hello.py and the output is as follows: The program will output a string to the terminal every second. If you type Ctrl+C at this time, the program will receive a SIGINT signal. If no special processing is done, the default behavior of the program is to terminate (as shown above). & Using python loop_hello.py &, the effect is as follows: First, the process number will be displayed in the terminal as 2367 Type Ctrl + C to send a SIGINT signal and the program will continue to run. When the session is closed, the program will receive a SIGHUP signal. You can see through ps aux | grep loop_hello.py that process 2367 is also closed. nohup Use nohup python loop_hello.py, the effect is as follows:
If I close the session, will the program close?
Test Ctrl + C Use nohup to start loop_hello.py. If you type Ctrl+C, the program will be closed directly after receiving the SIGINT signal. & and nohup are used together Use nohup python loop_hello.py & to run the program. The effect is as follows: Type Ctrl + C to send a SIGINT signal. Use ps aux to check that the process still exists. Close the session, send a SIGHUP signal and use ps aux to check that the process still exists If you want to terminate the process, you can only use kill Summarize: Use & to run the program in the background:
Run the program using nohup:
On weekdays, nohup and & are often used together to start programs online:
Well, that’s all for this article. I hope the content of this article will be of certain reference value to your study or work. Thank you for your support of 123WORDPRESS.COM. You may also be interested in:
|
<<: Ubuntu 18.04 installs mysql 5.7.23
>>: Tutorial on installing mysql5.7.23 on Ubuntu 18.04
What is NFS? network file system A method or mech...
1. Add alternative text to your logo This has two...
There is an interview question that requires: a th...
This post focuses on a super secret Flutter proje...
The Golden Rule Always follow the same set of cod...
Preface Before talking about covering index, we m...
This article aims to use the clearest structure t...
Table of contents 1. How to create an array in Ja...
Analyze the execution process. Move the mouse int...
This article example shares the specific code for...
Code Explanation 1.1 http:www.baidu.test.com defa...
1. Introduction After MySQL is started, BufferPoo...
Library Management Create a library create databa...
Rendering Example Code Today we are going to use ...
A few days ago, a colleague received a points mal...