The concept of a signal
Signal (signal)--the way communication between processes is a software interrupt. Once a process receives a signal, it interrupts the original program execution process to process the signal.
Several common signals:
SIGINT terminating process interrupt process (CONTROL+C)
Sigquit Exit Process
SIGTERM terminating process software termination signal (default signal)
SIGKILL Terminate process Kill process
SIGALRM Alarm Clock signal
For example, to do some processing when you press 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) The processing function used to register the semaphore,
The first parameter is the semaphore, the second argument can pass a function,
This function defaults to two parameters, the first parameter sig represents the received semaphore, and the second stack_frame can be understood as the call stack that produces the interrupt semaphore sig.