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
40
votes
4 answers

How can I tell in Linux which process sent my process a signal

I have a java application that got SIG TERM. I want to know the pid of the process that sent this signal. Is that possible?
oshai
  • 14,865
  • 26
  • 84
  • 140
40
votes
2 answers

How to handle a signal.SIGINT on a Windows OS machine?

I am trying the code pasted below on Windows, but instead of handling signal, it is killing the process. However, the same code is working in Ubuntu. import os, sys import time import signal def func(signum, frame): print 'You raised a SigInt!…
Ramu
  • 401
  • 1
  • 4
  • 6
40
votes
2 answers

How to signal an application without killing it in Linux?

I have a watchdog application. It watches my main app which might crash for one reason or another (I know it is bad, but this is not the point). I programmed this watchdog to accept SIGUSR1 signals to stop monitoring my application presence. I…
Eric
  • 19,525
  • 19
  • 84
  • 147
39
votes
6 answers

GDB: Ctrl+C doesn't interrupt process as it usually does but rather terminates the program

Normally when you run a program through GDB you can press Ctrl+C to interrupt it, e.g. if it gets stuck in an infinite loop and you want to get a backtrace. I'm debugging a program (xmms2d as it happens) but in this program only, when I press Ctrl+C…
Malvineous
  • 25,144
  • 16
  • 116
  • 151
38
votes
1 answer

How, in Perl 5, can I get the pid of the process who sent me a signal?

In C, I can say #include #include #include int continue_running = 1; void handler(int signal, siginfo_t* info, void* data) { printf("got signal %d from process %d running as user %d\n", signal,…
Chas. Owens
  • 64,182
  • 22
  • 135
  • 226
36
votes
1 answer

Is it possible to signal handler to survive after "exec"?

I wrote a signal handler for a process, and fork() after that, the signal handler will be applied to both parent and child processes. If I replace the child process with "exec", the signal handler is no more. I know this happens because "exec" call…
aditya
  • 952
  • 3
  • 16
  • 33
36
votes
3 answers

Ctrl + C interrupt event handling in Linux

I am developing an application that uses C++ and compiles using Linux GNU C Compiler. I want to invoke a function as the user interrupts the script using Ctrl + C keys. What should I do? Any answers would be much appreciated.
mozcelikors
  • 2,582
  • 8
  • 43
  • 77
35
votes
5 answers

What does SEGV_ACCERR mean?

I am examining a few crashes that all have the signal SIGSEGV with the reason SEGV_ACCERR. After searching for SEGV_ACCERR, the closest thing I have found to a human readable explanation is: Invalid Permissions for object What does this mean in a…
Saltymule
  • 2,907
  • 2
  • 22
  • 30
35
votes
5 answers

C++11 observer pattern (signals, slots, events, change broadcaster/listener, or whatever you want to call it)

With the changes made in C++11 (such as the inclusion of std::bind), is there a recommended way to implement a simple single-threaded observer pattern without dependence on anything external to the core language or standard library (like…
learnvst
  • 15,455
  • 16
  • 74
  • 121
34
votes
4 answers

How to cleanly exit a threaded C++ program?

I am creating multiple threads in my program. On pressing Ctrl-C, a signal handler is called. Inside a signal handler, I have put exit(0) at last. The thing is that sometimes the program terminates safely but the other times, I get runtime error…
rjlion795
  • 515
  • 1
  • 5
  • 16
34
votes
2 answers

How to gracefully terminate an asyncio script with Ctrl-C?

I've read every post I could find about how to gracefully handle a script with an asyncio event loop getting terminated with Ctrl-C, and I haven't been able to get any of them to work without printing one or more tracebacks as I do so. The answers…
JK Laiho
  • 3,538
  • 6
  • 35
  • 42
34
votes
2 answers

How can i use signals in django bulk create

I have this code Task.objects.bulk_create(ces) Now this is my signal @receiver(pre_save, sender=Task) def save_hours(sender, instance, *args, **kwargs): logger.debug('test') Now this signal is not triggered in bulk create I am using django 1.8
user3214546
  • 6,523
  • 13
  • 51
  • 98
34
votes
1 answer

Can I manually trigger signals in Django?

I've written some signals in my Django app that are supposed to send out an email when a particular model instance is created or modified, but the signal receiver function doesn't seem to be responding; at any rate, I'm not getting any emails…
david_hughes
  • 712
  • 2
  • 7
  • 9
33
votes
2 answers

How do I send a signal to a `Child` subprocess?

Child::kill sends a SIGKILL, but how can I send any other signal such as SIGTERM? I can probably use libc and its signal API, but is there a better way to do this?
Oleg Antonyan
  • 2,943
  • 3
  • 28
  • 44
33
votes
2 answers

How can I send a signal from a python program?

I have this code which listens to USR1 signals import signal import os import time def receive_signal(signum, stack): print 'Received:', signum signal.signal(signal.SIGUSR1, receive_signal) signal.signal(signal.SIGUSR2, receive_signal) print…
user192082107
  • 1,277
  • 4
  • 15
  • 19