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

Handling SIGTSTP signals in C

I came across this example code in my studies: #include #include #include char* nums[5] = {"One", "Two", "Three", "Four", "Five"}; char number[6]; void handler(int n) { printf(" %s\n", number); } int main() { …
Edmis
  • 31
  • 1
  • 1
  • 3
3
votes
1 answer

Restore serial port attributes even after control-C?

When using a serial port via POSIX, it's recommended to save the original attributes using tcgetattr() before changing them with tcsetattr(), and then restore them before closing the port. What about when a program is terminated by pressing…
Shay Green
  • 41
  • 2
3
votes
1 answer

How do you handle Ctrl+Break in Python?

In Python you can handle Ctrl+C with KeyboardInterrupt, but how do you handle Ctrl+Break?
Junior
  • 165
  • 1
  • 1
  • 10
3
votes
1 answer

Letting a child know that it should update its state in React

I'm trying to let a child Component know that it should update its state after a prop change in the parent. There is no state that needs to be shared between the two. The only thing that needs to happen is that the parent should somehow let the…
Robin_f
  • 445
  • 5
  • 14
3
votes
2 answers

Capture the pid of signal sender

local $SIG{INT} = \&handle_sigint; sub handle_sigint { print "received sigint\n"; } in handle_sigint i would like to print who (pid/process name) sent the signal. Is there a way to capture that info in perl? i can do this in C and this is…
ealeon
  • 12,074
  • 24
  • 92
  • 173
3
votes
1 answer

How does shell/kernel handle signals sent to processes within same process group?

In the section 9.6 of Advanced Programming in the UNIX environment we can read: Whenever we press the terminal’s interrupt key (often DELETE or Control-C), the interrupt signal is sent to all processes in the foreground process group. I did a…
Maro
  • 91
  • 1
  • 5
3
votes
2 answers

Can I Force MATLAB to quit after user presses Control-C?

I'm running MATLAB (command line version) from a shell script, and I'd like it to preserve shell behavior where if you press Ctrl-C it exits. But instead it wants to keep control of the terminal and I (or my poor users after me) have to type…
rescdsk
  • 8,739
  • 4
  • 36
  • 32
3
votes
4 answers

QListView selectionModel not sending selectionChanged signal

I have an interface with two QListViews, where the left determines what is displayed in the right: To update the list on the right, I have the following function: void CodePlug::handleSelectionChanged() { QModelIndex portIndex =…
Magrias
  • 275
  • 1
  • 3
  • 14
3
votes
1 answer

Psycopg2 connection unusable after SELECTs interrupted by OS signal

Problem I am working on a long-running python process that performs a lot of database access (mostly reads, occasional writes). Sometimes it may be necessary to terminate the process before it finishes (e.g. by using the kill command) and when this…
mactyr
  • 463
  • 3
  • 16
3
votes
2 answers

signal handler in child thread

I tried to install SIGINT handler for the child thread in the code below. I expect the child thread to print hello when it receives SIGINT from the parent process. However, nothing comes out and the program exits immediately. #include…
HuangJie
  • 1,488
  • 1
  • 16
  • 33
3
votes
2 answers

Pass arguments to signal handler in C

How can I pass arguments (e.g. a pointer to a struct) to a signal handler? I'm writing a multithread application, so I cannot use global variables I associate a timer to each thread. When timer expires I have to update a struct (each thread has a…
WindowsEFI
  • 31
  • 1
  • 5
3
votes
1 answer

wxPython handling SIGTERM / SIGINT

I have a wxPython app. I want it to respond to SIGTERM and SIGINT just like as if the "close" button had been clicked. However, when I bind the signals using signal.signal(signal.SIGTERM, exit_handler), they only get executed after an event is sent…
randomdude999
  • 701
  • 7
  • 20
3
votes
2 answers

How to convert SIGFPE into a C++-exception

Under Win32 it's easy to convert a SEH-exception into a C++-exception with _set_se_translator. Is there a similar way to convert certain signals into C++-exceptions on Linux? I need a mapping of SIGFPE to a C++-exception.
Bonita Montero
  • 2,817
  • 9
  • 22
3
votes
1 answer

When debugging, can I make Xcode ignore certain signal?

I am making some development on Xcode for a OS X application. I need to send SIGUSR1 to the application by: kill(getpid(), SIGUSR1) This worked. However, each time the SIGUSR1 sent, Xcode was blocked to show me that a signal was caught. Can I…
Andrew Chang
  • 1,289
  • 1
  • 18
  • 38
3
votes
0 answers

How to dynamically set number of threads using OpenMp

I am trying to control running threads using OpenMp. What I need is to set number of running threads according to certain condition. I am using signal handler to control the thread. I have written the following…
Chinnu
  • 85
  • 10