In the C Standard Library, signal processing defines how a program handles various signals while it executes. A signal can report some exceptional behavior within the program (such as division by zero), or a signal can report some asynchronous event outside the program (such as someone striking an interactive attention key on a keyboard).
Questions tagged [signal-handling]
290 questions
3
votes
2 answers
How to have more than two consecutive signals caught?
If I send multiple subsequent Hangup signals to the following program, only two of them would be handled and the rest will be ignored:
#include
#include
#include
int id;
void handler(int s)
{
id++;
int i;
…

B Faley
- 17,120
- 43
- 133
- 223
3
votes
1 answer
How to delete shared memory when ctrl c?
I write a shm struct as following:
class ShmWorker {
public:
ShmWorker() = default;
virtual ~ShmWorker() {
shmdt(m_data);
shmctl(shmid, IPC_RMID, 0); // here is the problem, if ctrl-c, the shared memory
// won't be…

nick
- 832
- 3
- 12
3
votes
2 answers
How to fire Java method using bash
Suppose I launch a Java application:
java -cp whatever.jar com.example.Start
Process launches ok and keeps running with PID 1314.
Now I would like the system to fire a method by users request.
How can I use bash to signal the running PID and have it…

Frankie
- 24,627
- 10
- 79
- 121
3
votes
1 answer
Threaded perl and signal handlers
I am using the Thread::Pool module in perl to parallelize some perl code. This process takes a while and occasionally I will kill it from the command line with a SIGINT. Doing so causes the program to end abruptly, as I expected. This leaves some…

pythonic metaphor
- 10,296
- 18
- 68
- 110
3
votes
2 answers
Why is my pipe in C not working?
as an exercise I need to use a signal handler, and pipes to send some messages between two processes, when getting a signal. Below is my sourcecode. When I'm running it, I can get the pipes to work, both processes can talk, as long as I call the…

Sietse Ludger G
- 33
- 3
3
votes
0 answers
Is local static variable initialization AS Safe in signal handler (Async Signal Safe)?
I wonder which I can use in my signal handler?
void my_signal_handler(int signo, siginfo_t* info, void* arg) {
static std::atomic_flag my_flag = ATOMIC_FLAG_INIT;
if (my_flag.test_and_set()) {
...
} else {
...
}
…

Justin
- 693
- 1
- 5
- 7
3
votes
1 answer
python forward SIGINT to subprocess
Here is a simple Python script that spawn a process:
import subprocess
import os
subprocess.run(['ping', '-i', '30', 'google.fr'],
preexec_fn=lambda : os.setpgrp())
When I kill -TERM , it stops the python process, but…

David Froger
- 645
- 6
- 15
3
votes
2 answers
Signal handling in asm: Why am I receiving SIGSEGV when invoking the sys_pause syscall?
I am trying to create an x86_64 assembly program that displays "SIGTERM received" whenever the SIGTERM signal is sent. My application is using Linux syscalls directly:
%define sys_write 0x01
%define sys_rt_sigaction 0x0d
%define sys_pause …

Nathan Osman
- 71,149
- 71
- 256
- 361
3
votes
4 answers
Handling synchronous signals
I'm trying to find resources talking about handling synchronous signals (SIGSEGV, SIGILL etc.) compared to handling async signals.
The typical signal handling mechanism (using kill, for example) invokes signal handlers on control transfer from…

Shrikant Giridhar
- 379
- 4
- 14
3
votes
1 answer
Python script can't be terminated through Ctrl+C or Ctrl+Break
I have this simple python script called myMain.py to execute another python program automatically with incremental number, and I'm running it on CentOS 7:
#!/usr/bin/python
import os
import sys
import time
def main():
step_indicator = ""
…

RandomEli
- 1,527
- 5
- 30
- 53
3
votes
2 answers
Linux x64 stack unwinding inside signal handler, to modify return address
I'm trying to modify a return address (some levels down) on the call stack. I need to do this when I am inside a signal handler. Therefore I'm doing the following:
#include
#include
#include
// To print…

datosh
- 498
- 7
- 20
3
votes
1 answer
Is it safe to use `std::shared_ptr` and `std::weak_ptr` in a signal handler?
I know it is not safe for malloc or free to be called, directly or indirectly, from a signal handler.
But, if I can guarantee that at least one shared reference will remain alive, is it then safe to copy-construct and destruct additional shared or…

o11c
- 15,265
- 4
- 50
- 75
3
votes
1 answer
Daemon shutdown and cleanup
I have a small Perl daemon that I'm refactoring and I have a best practice question.
The daemon writes out a pid file when it starts up and should remove it when it shuts down.
Would you recommend putting the pid file deletion code in a signal…

Sean O'Leary
- 304
- 1
- 9
3
votes
1 answer
munmap anonymous shared memory in forked child
i'd like to know if it is necessary (or advisable) to unmap shared memory (using munmap) in child created via fork, if the memory was obtained in the parent, before the fork, using mmap(..., MAP_ANONYMOUS | MAP_SHARED,...) and will also be unmapped…
user4259083
3
votes
1 answer
How to change FPU context in signal handler (C++/Linux)
I wrote a signal handler to catch FPE errors. I need to continue execution even if this happens. I receive a ucontext_t as parameter, I can change the bad operand from 0 to another value but the FPU context is still bad and I run into an infinite…

Henry Fané
- 93
- 2
- 7