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
Benefits of Prepare The reason why Prepare SQL is...
Note: You cannot use scoped animations! ! ! ! via...
The <TH> tag is used to set the properties ...
Install Filebeat has completely replaced Logstash...
Table of contents Preface: 1. Introduction to rol...
I was recently working on a project about face co...
Data Types and Operations Data Table 1.1 MySQL ty...
Table of contents 1. switch 2. While Loop 3. Do/W...
1. The startup menu is to move the cursor to the ...
Copy code The code is as follows: @charset "...
Note: All pictures in this article are collected ...
1. Cause The requirement is to display two lines,...
Table of contents Preface 1. Basic Environment 1....
Implementation effect: 1. count(1) and count(*) W...
This article example shares the specific code of ...