Questions tagged [signals]

A signal is a notification to a process that an event occurred. Signals are sometimes described as software interrupts. Signals are analogous to hardware interrupts in that they interrupt the normal flow of execution of a program; in most cases, it is not possible to predict exactly when a signal will arrive. They are defined in the C standards and extended in POSIX, but many other programming languages/systems provide access to them as well.

Standards

These standards actually place requirements on the signal-handling facilities:

C++11 essentially says that you get the same facilities as in C, as long as you restrict signal handlers to the common subset of C and C++, and use C linkage for them. Quoting n3242 section 18.10 "Other runtime support" [support.runtime] (paragraph 8),

The common subset of the C and C++ languages consists of all declarations, definitions, and expressions that may appear in a well formed C++ program and also in a conforming C program. A POF (“plain old function”) is a function that uses only features from this common subset, and that does not directly or indirectly use any function that is not a POF, except that it may use functions defined in Clause 29 that are not member functions. All signal handlers shall have C linkage. A POF that could be used as a signal handler in a conforming C program does not produce undefined behavior when used as a signal handler in a C++ program. The behavior of any other function used as a signal handler in a C++ program is implementation-defined.

7326 questions
47
votes
3 answers

Python: What is the default handling of SIGTERM?

What does Python do under the covers by default if it receives a SIGTERM but there is no signal handler registered for it?
meteoritepanama
  • 6,092
  • 14
  • 42
  • 55
47
votes
4 answers

How to send signal to program run in a docker container?

I have a program run in a docker container with detached mode. So how to send a signal such as SIGINT to this program?
atupal
  • 16,404
  • 5
  • 31
  • 42
47
votes
3 answers

Capture SIGINT in Java

What is the best way to capture a kill signal in java without using JNI. I did discover the sun.misc.Signal and the sun.misc.SignalHandler and the warning of the possibility of being removed in the future releases. Would using JNI to call a c lib…
Begui
  • 2,726
  • 3
  • 22
  • 17
46
votes
4 answers

Is Python variable assignment atomic?

Let's say I am using a signal handler for handling an interval timer. def _aHandler(signum, _): global SomeGlobalVariable SomeGlobalVariable=True Can I set SomeGlobalVariable without worrying that, in an unlikely scenario that whilst setting…
jldupont
  • 93,734
  • 56
  • 203
  • 318
46
votes
1 answer

Debugging child process after fork (follow-fork-mode child configured)

I'm developing an application which the parent forks a child to handle certain tasks. I'm having an issue where I've configured gdb to follow-fork-mode child but after fork, after reaching a breakpoint, it sends a SIGTRAP but the child somehow…
ihsan
  • 551
  • 1
  • 5
  • 10
45
votes
5 answers

Python: How to prevent subprocesses from receiving CTRL-C / Control-C / SIGINT

I am currently working on a wrapper for a dedicated server running in the shell. The wrapper spawns the server process via subprocess and observes and reacts to its output. The dedicated server must be explicitly given a command to shut down…
robert
  • 3,484
  • 3
  • 29
  • 38
45
votes
5 answers

Making sure a Python script with subprocesses dies on SIGINT

I've got a command that I'm wrapping in script and spawning from a Python script using subprocess.Popen. I'm trying to make sure it dies if the user issues a SIGINT. I could figure out if the process was interrupted in a least two ways: A. Die if…
ajwood
  • 18,227
  • 15
  • 61
  • 104
45
votes
7 answers

Segmentation fault handling

I have an application which I use to catch any segmentation fault or ctrl-c. Using the below code, I am able to catch the segmentation fault but the handler is being called again and again. How can I stop them. For your information, I don't want…
user1225606
  • 1,123
  • 2
  • 14
  • 14
44
votes
2 answers

PyQt proper use of emit() and pyqtSignal()

I am reading through some documentation on PyQt5 to come up with a simple signal-slot mechanism. I have come to a halt due to a design consideration. Consider the following code: import sys from PyQt5.QtCore import (Qt, pyqtSignal) from…
Max
  • 2,072
  • 5
  • 26
  • 42
44
votes
6 answers

How does sig_atomic_t actually work?

How does the compiler or OS distinguish between sig_atomic_t type and a normal int type variable, and ensures that the operation will be atomic? Programs using both have same assembler code. How extra care is taken to make the operation atomic?
Chu
  • 620
  • 1
  • 8
  • 14
44
votes
3 answers

Alternative to sun.misc.Signal

I started research to find an alternative to the sun.misc.Signal class, because it could be unsupported in upcoming JDKs (we're currently working on 1.6). When I build the project I get: warning: sun.misc.SignalHandler is Sun proprietary API and…
plancys
  • 3,833
  • 2
  • 19
  • 26
44
votes
4 answers

Python: Catch Ctrl-C command. Prompt "really want to quit (y/n)", resume execution if no

I have a program that may have a lengthy execution. In the main module I have the following: import signal def run_program() ...time consuming execution... def Exit_gracefully(signal, frame): ... log exiting information ... ... close…
Colin M
  • 441
  • 1
  • 4
  • 3
44
votes
1 answer

Permanently configuring LLDB (in Xcode 4.3.2) not to stop on signals

I'm trying to get LLDB (running in Xcode 4.3.2 with an OS X application) to not stop on certain signals. If I enter process handle SIGUSR2 -n true -p true -s false on the debugging console it works fine and LLDB no longer stops on SIGUSR2. However,…
puzzle
  • 6,071
  • 1
  • 25
  • 30
43
votes
3 answers

Golang catch signals

I want to implement a "process wrapper" in Go. Basically what it will do, is launch a process (lets say a node server) and monitor it (catch signals like SIGKILL, SIGTERM ...) I think the way to do is to launch the node server in a go routine using…
rmonjo
  • 2,675
  • 5
  • 30
  • 37
41
votes
1 answer

What does WEXITSTATUS(status) return?

I am trying to understand how WEXITSTATUS(status) works. I have come across a piece of code where the return value of WEXITSTATUS(status) is being added to a variable. Here is the snippet: waitpid(-1, &status, 0); counter +=…
shaveenk
  • 1,983
  • 7
  • 25
  • 37