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
3
votes
1 answer

Workaround to Q_PROPERTY NOTIFY with inherited signal

It is known that an inherited signal cannot be used as a Q_PROPERTY NOTIFYer (https://bugreports.qt.io/browse/QTBUG-7684). As a workaround I'm using an extra signal in the derived class that gets fired when the base signal gets fired. The base…
Ayberk Özgür
  • 4,986
  • 4
  • 38
  • 58
3
votes
3 answers

SIGSEGV handler can not exit

I registered a handler of SIGSEGV, using fprintf to print some message then exit. The process prints the message but did not exit. It blocked before exit(). Can't I use exit() to finish the process normally in the handler? void sigsegv__handler(){ …
wangbo15
  • 191
  • 1
  • 13
3
votes
3 answers

LInux signals concepts

How signal handler takes the signal number without passing arguments to signalhandler() function in main()? For example in the below source code inside main() passing 2nd argument of signal system call as signalhandler without any argument in…
raj
  • 33
  • 5
3
votes
0 answers

How to signal a specific thread in Windows

I have an application in which I iterate over an array of threads, each of which needs to be sent a specific signal. In Linux, this would look something like the following: // my_threads is a vector of std::thread objects for (auto i =…
Byte Lab
  • 1,576
  • 2
  • 17
  • 42
3
votes
3 answers

Is it good style to memset a struct before using it?

Once I learned signals and there was a listing with handling signals. There was a struct sigaction which was first memset() to all bytes zero with the following line: memset(&sa, 0, sizeof(sa)); And I'm not sure why author uses this approach.
user3524337
  • 462
  • 6
  • 17
3
votes
1 answer

django Signals launched twice when action is done in admin

I've a simple signals which is launch when the object is deleted @receiver(post_delete, sender=Operation, dispatch_uid="delete_operation") def delete_operation(sender, instance, **kwargs): # Track balance operations for delete …
DaschPyth
  • 195
  • 1
  • 2
  • 9
3
votes
2 answers

How do I send a signal to Perl on Windows?

I have some perl code which establishes a signal handler: $SIG{'KILL'} = sub { .... }; I'm tasked with porting this to windows and I was wondering how I could generate this signal from a C# class. I saw the Process.Kill method in the…
tzenes
  • 1,699
  • 2
  • 15
  • 31
3
votes
1 answer

How do Boost Bind, Boost Function, Boost Signals and C++ function pointers all relate to each other?

As the title might convey, I'm having problems seeing how Boost Bind, Boost Function, Boost Signals and C++ function pointers all play together. From my understanding, Boost Bind and Boost Function in conjunction work like Signals while Signals is…
svenstaro
  • 1,783
  • 2
  • 21
  • 31
3
votes
2 answers

is static thread_local memory async signal safet in c++14?

Let's assume that I have this function: int my_thread_id(){ static int counter {0}; thread_local int tid{++counter}; return tid; } Is this function (my_thread_id) async-signal-safe, even on the first call?
Mae Milano
  • 714
  • 4
  • 14
3
votes
1 answer

How to implement template class with template-dependent signal member from boost?

I try to implement a template class which requires to have a signal member that depends on the template argument. My first idea was to realize it like the following: template class SignalClass { typedef boost::signals2::signal
user440773
  • 33
  • 5
3
votes
0 answers

iOS global catch all crash

I want to save some data when app crashed, which I means not only the Exception and some signal. I already implement the method NSSetUncaughtExceptionHandler(&HandleException); signal(SIGABRT, SignalHandler); signal(SIGILL,…
Benjamin
  • 99
  • 6
3
votes
1 answer

how to block same signal while processing a signal?

I programmed a daemon which usually pauses and do something after getting a signal (I use SIGHUP for waking up it to another process). Here is my code. ... static volatile sig_atomic_t saw_hup = 0; static void sighup_handler(int s) { saw_hup =…
SB.Son
  • 31
  • 6
3
votes
1 answer

How can I handle or detect a system signal in D?

D's (rather sparse) official documentation doesn't have anything about handling system signals on *nx or Windows. The system module only has Endian and OS, syserror is deprecated / only for Windows errortext, and signals is about message-passing,…
cat
  • 3,888
  • 5
  • 32
  • 61
3
votes
1 answer

Get function name that made a (illegal) memory access

For debugging reasons I am trying to print the name of the function that made an illegal memory access (out of range for example). I have written a SIGSEGV signal handler to print the Instruction Pointer (IP) and the faulted memory address, but I…
Florin Avram
  • 167
  • 1
  • 7
3
votes
3 answers

how to get stdout of subprocess in python when receving SIGUSR2 /SIGINT

I have the following simple python script: import os, subprocess,signal,sys import time out = None sub = None def handler(signum,frame): print("script.py: cached sig: %i " % signum) sys.stdout.flush() if sub is not None and not…
Gabriel
  • 8,990
  • 6
  • 57
  • 101