Questions tagged [signal-handling]

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).

290 questions
4
votes
1 answer

Handling segmentation fault due to a C++ subprocess spawned by Python code

I have read a few articles about signal handling in Python, and for some reason am not getting the desired output. This is my C++ code. It is meant to simulate a segmentation fault. The purpose of the Python code is to run the C++ program as a…
4
votes
1 answer

How to properly write a SIGPROF handler that invokes AsyncGetCallTrace?

I am writing a short and simple profiler (in C), which is intended to print out stack traces for threads in various Java clients at regular intervals. I have to use the undocumented function AsyncGetCallTrace instead of GetStackTrace to minimize…
user400348
  • 236
  • 2
  • 7
4
votes
3 answers

Is read-only access to a vector (vector::operator[] and vector::size()) asynchronous-safe?

My program needs to perform read-only access to the contents of a vector in a signal handler for SIGINT. (The alternative is to use a fixed-size array of fixed-length C strings.) The program is designed to run in a POSIX environment. Are…
bwDraco
  • 2,514
  • 2
  • 33
  • 38
4
votes
2 answers

Create signal handler for a single thread

I'm wondering if sigaction will create a signal handler for the calling thread or the whole process. If it unblocks a signal and creates a signal handler for the entire process, then how can I make sure only a single thread will use the signal…
sj755
  • 3,944
  • 14
  • 59
  • 79
4
votes
2 answers

Strange sigaction() and getline() interaction

I have a signal handler set up using sigaction like so: struct sigaction act, oldact; memset(&act, 0, sizeof(struct sigaction)); act.sa_handler = sig_handler; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGALRM); sigaddset(&act.sa_mask,…
Connor
  • 156
  • 1
  • 11
4
votes
0 answers

Using swapcontext with signal handler

I am trying to build a user level thread library like pthreads. I want to use swapcontext within the signal handler. But since it is not a signal safe function, it is not advisable to use it. Can somebody suggest how to use it inside the signal…
Poojan
  • 3,312
  • 4
  • 20
  • 23
4
votes
1 answer

APR threads and signal handling

I am currently trying to implement threads using the Apache Portable Runtime. Everything works fine, except I am not really sure if I am doing it the way it's intended to do due to lack of documentation or examples. I need two threads and signal…
padde
  • 661
  • 8
  • 19
4
votes
1 answer

Python Unix/Windows Abstraction Layer for Signal Handling & User Management

I'd like to ask a question for which my extensive web search would suggest the answer is 'no' but maybe I've overlooked something ... Are there Python abstraction layers sitting on top of Unix and Windows signal handling (for spawned, independent…
4
votes
1 answer

Getting back trace for ARC platform from signal handler context

I want to catch SIGSEGV and print the back trace in the logs before my program exits. This is to analyze the crash at a later point of time. I am working on a software which runs on multiple platforms. On x86 platform I can do this easily by using…
CCoder
  • 2,305
  • 19
  • 41
4
votes
1 answer

Where is uc_mcontext definition?

The third parameter of sa_sigaction is a pointer which point to a machine-dependent struct ucontext, I would like to know what I can dump from struct ucontext. void (*sa_sigaction)(int signum, siginfo_t *info, void *ucontext) struct ucontext { …
chenwj
  • 1,989
  • 2
  • 16
  • 30
4
votes
2 answers

Should we use perror inside signal handler

should we use perror inside signal handler because they have a user space buffer like printf and other stdio functions?
Majid Azimi
  • 5,575
  • 13
  • 64
  • 113
4
votes
3 answers

Process group for child processes of a library

I'm working on a library (C++) that will be integrated into clients code. This lib will spawn a few child processes and must monitor them to respawn them as soon as they die (for any reason). I need to use vfork and exec to spawn those child…
Marcus
  • 1,675
  • 3
  • 18
  • 29
4
votes
1 answer

safe to access shared data structure from signal handler

I'm trying to decide wether it's safe to access a common (read: shared between handler-code and rest of the programm) data structure from a signal handler in perl (v5.14.2) built for x86_64-linux-thread-multi, but target platform is…
sschober
  • 2,003
  • 3
  • 24
  • 38
3
votes
0 answers

Java and signals

When programming in C or Perl, a SIGALRM signal can interrupt 'print' in such a way that only a partial write occurs. Is there any such hassle with signals when using Java? Or does the JVM shield the programmer from any side-effects?
user1050755
  • 11,218
  • 4
  • 45
  • 56
3
votes
2 answers

Correct way to use signal handlers

What is the correct way to use signal handlers? I saw the codes below from this question and was wondering why do you still need to put signal(SIGSEGV,sig_func); inside the sig_func? Wouldn't that create an unending loop when the process receives a…
kuchi
  • 840
  • 11
  • 19