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
95
votes
3 answers

Calling pthread_cond_signal without locking mutex

I read somewhere that we should lock the mutex before calling pthread_cond_signal and unlock the mutex after calling it: The pthread_cond_signal() routine is used to signal (or wake up) another thread which is waiting on the condition variable. It…
B Faley
  • 17,120
  • 43
  • 133
  • 223
95
votes
3 answers

Catch Ctrl+C / SIGINT and exit multiprocesses gracefully in python

How do I catch a Ctrl+C in multiprocess python program and exit all processes gracefully, I need the solution to work both on unix and windows. I've tried the following: import multiprocessing import time import signal import sys jobs = [] def…
zenpoy
  • 19,490
  • 9
  • 60
  • 87
93
votes
7 answers

How to suspend/resume a process in Windows?

In Unix we can suspend a process execution temporarily and resume it with signals SIGSTOP and SIGCONT. How can I suspend a single-threaded process in Windows without programming ?
Michael
  • 41,026
  • 70
  • 193
  • 341
86
votes
7 answers

Django: signal when user logs in?

In my Django app, I need to start running a few periodic background jobs when a user logs in and stop running them when the user logs out, so I am looking for an elegant way to get notified of a user login/logout query user login status From my…
ssc
  • 9,528
  • 10
  • 64
  • 94
85
votes
4 answers

POSIX threads and signals

I've been trying to understand the intricacies of how POSIX threads and POSIX signals interact. In particular, I'm interested in: What's the best way to control which thread a signal is delivered to (assuming it isn't fatal in the first…
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
84
votes
6 answers

Why can't Unix programs have signals with meaningful program defined names (rather than USR1, etc)?

Many Unix programs accept signals like USR1 and USR2. For example, to upgrade the executable for Nginx on the fly, you send kill -USR2. I understand that USR1 is a "user defined" signal, meaning that whoever created the program can use it to mean…
Nathan Long
  • 122,748
  • 97
  • 336
  • 451
83
votes
6 answers

Where are core dumps written on Mac?

On Mac OS X, if I send SIGQUIT to my C program, it terminates, but there is no core dump file. Do you have to manually enable core dumps on Mac OS X (how?), or are they written to somewhere else instead of the working directory?
xyz
  • 27,223
  • 29
  • 105
  • 125
82
votes
9 answers

What is the correct way to make my PyQt application quit when killed from the console (Ctrl-C)?

What is the correct way to make my PyQt application quit when killed from the console (Ctrl-C)? Currently (I have done nothing special to handle unix signals), my PyQt application ignores SIGINT (Ctrl+C). I want it to behave nicely and quit when it…
static_rtti
  • 53,760
  • 47
  • 136
  • 192
81
votes
2 answers

How and why does QuickEdit mode in Command Prompt freeze applications?

I recently ran into an issue with Command Prompt on Windows where QuickEdit mode was enabled and clicking the window was selecting text and hanging a running program. This is, apparently, known behaviour—I found a few questions related to…
Whymarrh
  • 13,139
  • 14
  • 57
  • 108
79
votes
8 answers

Providing/passing argument to signal handler

Can I provide/pass any arguments to signal handler? /* Signal handling */ struct sigaction act; act.sa_handler = signal_handler; /* some more settings */ Now, handler looks like this: void signal_handler(int signo) { /* some code */ } If I…
hari
  • 9,439
  • 27
  • 76
  • 110
75
votes
1 answer

Pusher vs Pubnub vs open source Socket.io / SignalR.net / Faye / jWebSocket

I'm evaluating Pusher and PubNub at the moment to enable bi-directional realtime communications between my primarily web clients and my servers. Both look impressive, with Pusher's docs seeming to be better, and PubNub's scalability and reliability…
Matthew O'Riordan
  • 7,981
  • 4
  • 45
  • 59
73
votes
9 answers

How to capture Control+D signal?

I want to capture the Ctrl+D signal in my program and write a signal handler for it. How can I do that? I am working on C and using a Linux system.
Ryan
72
votes
10 answers

Android Fatal Signal 11

In the app I'm developing on Android, I keep getting a Fatal Signal 11 error. I think it's something to do with the way that I'm accessing the memory but I can't figure out what is causing it. Here's the LogCat: 05-02 23:47:17.618: D/dalvikvm(590):…
Declan Greally
  • 1,083
  • 1
  • 9
  • 13
71
votes
7 answers

No overload matches this call. Type 'string' is not assignable to type 'Signals'

I am using typescript to build a microservice and handling signals as well. The code was working fine till a few days ago but recently it started throwing errors. Couldn't find a fix for the issue. code for handling signals. It is just part of the…
M A SIDDIQUI
  • 2,028
  • 1
  • 19
  • 24
70
votes
2 answers

Run one command after another, even if I suspend the first one (Ctrl-z)

I know in bash I can run one command after another by separating them by semicolons, like $ command1; command2 Or if I only want command2 to run only if command1 succeeds, using &&: $ command1 && command2 This works, but if I suspend command1…
asmeurer
  • 86,894
  • 26
  • 169
  • 240