The concept of signal
Signal (signal) - The way of communication between processes is a software interrupt. Once a process receives a signal, it interrupts the original program execution flow to handle the signal.
Several common signals:
SIGINT use using using using using using using using using out out out out out off out out out out out out out out out of ‐ in ‐ ‐ ‐SIGINT SIGALRM alarm clock signal
For example, if you want to do some processing when pressing control+c to terminate the process, the code is as follows:
import signal
def fun(sig, stack_frame):
print 'eixt %d, %s' % ( sig,stack_frame)exit(1)
signal.signal(signal.SIGINT, fun)
signal.signal(signal.SIGINT, fun) is used to register the processing function of the semaphore,
the first parameter It is a semaphore. The second parameter can be passed to a function. This function has two parameters by default. The first parameter sig represents the received semaphore. The second stack_frame can be understood as the call stack that generates the interrupt semaphore sig. .