NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle+82 views

Что такое сигналы, которые можно посылать процессу?

Practice

AI answer

Signals are an operating system mechanism for asynchronously notifying a process about an event. They can occur, for example, when Ctrl+C is pressed in a terminal (SIGINT), when a process is terminated (SIGTERM), or when an error occurs, such as an invalid operation (SIGSEGV). Some signals can be handled or ignored, but SIGKILL cannot be caught or canceled.

On Unix-like systems, Python's signal module lets you register a handler, for example:

import signal

def handle_sigint(signum, frame):
    print("SIGINT received")

signal.signal(signal.SIGINT, handle_sigint)

In CPython, signal handlers usually run in the interpreter's main thread; therefore, a signal is not a general way to safely interrupt an arbitrary thread. To shut down a process gracefully, SIGTERM is often handled by setting a shutdown flag and releasing resources.