Example of commonly used signal type in Python, pythonsignal
This article focuses on the Signal in Python, as detailed below.
Common signal types
- SIGINT terminates the process to interrupt the process and cannot be captured through signal. signal () (equivalent to Ctrl + C)
- The software termination signal of the SIGTERM termination process, which can be captured through signal. signal () (default signal, which is the default signal when OS. kill () does not specify the signal type)
- SIGKILL terminates the process and kills the process. It cannot be captured (equivalent to the kill command in linux, which throws an exception when used in windows)
- The SIGALRM alarm signal can be sent through signal. alarm () and OS. kill (), which can be captured through signal. signal ().
- Similar to SIGTERM, a sigquit exit process can be captured through signal. signal ().
A. py
# Coding = utf8 import signal, OS, time def onsignal_term (a, B): print 'receive SIGTERM sign' def onsignal_quit (a, B ): print 'receive SIGQUIT signal 'def onsignal_alrm (a, B): print 'receive SIGALRM signal' signal. signal (signal. SIGTERM, onsignal_term) signal. signal (signal. SIGQUIT, onsignal_quit) signal. signal (signal. SIGALRM, onsignal_alrm) signal. alarm (10) while 1: print 'process id: ', OS. getpid () time. sleep (2)
B. py
Import OS, signal, time OS. kill (5097, signal. SIGTERM) time. sleep (5) # The OS does not work if the signal after the process is terminated. kill (4976, signal. SIGINT) OS. kill (5006, signal. SIGKILL) OS. kill (5071, signal. SIGQUIT) OS. kill (5097, signal. SIGALRM)
Summary
The above is all the content of the signal type instances commonly used in Python, and I hope to help you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!