Python Signal Volume

Source: Internet
Author: User
Tags semaphore

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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.