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
6
votes
3 answers
C++ exceptions and signal handlers
I am reading The Design and Evolution of C++, by Bjarne Stroustrup. Regarding exeception handling and asynchronous signals it is mentioned as below:
Can exceptions be used to handle things like signals? Almost certainly not in most C environments.…

venkysmarty
- 11,099
- 25
- 101
- 184
6
votes
3 answers
is execution of signal handler un-preemptible in linux?
I have a process p registered with a signal handler for SIGALRM. A timer is setup to periodically send signal SIGALRM to process p. There are also multiple threads running in process p. Is the signal handler, when being triggered and executed,…

Richard
- 14,642
- 18
- 56
- 77
6
votes
3 answers
calling signal after fork
Is there any difference between "code listing 1" and "code listing 2"? Because in Code Listing 1, the child process is able to catch the SIGTERM signal and exit nicely. But code listng 2 is terminating abruptly on SIGTERM signal.
I am using Linux…

Sabya
- 11,534
- 17
- 67
- 94
6
votes
3 answers
Get Keyboard Interrupt in C
Program:
#include
void main()
{
int time=1800;
while(1){
system("clear");
time-=1;
printf("%d\n",time);
sleep(1);
if(time==0)
pause();
}
}
The above program stops when the time…

mohangraj
- 9,842
- 19
- 59
- 94
6
votes
1 answer
Signal handling among pthreads
I am trying to learn signal handling among processes and threads. The answer to a few questions would help me understand it better.
I know that a process can send a signal to the process group and allow multiple processes to receive the same…

OwlsCIS
- 61
- 4
6
votes
1 answer
How do I handle and move past a segfault?
I'm working on a project in C involving linked lists, and I need to segfault a piece of code in order to prove it doesn't work. But my code can't crash.
Here's my handler so far:
typedef void sigfunc(int);
sigfunc *signal(int, sigfunc*);
void…

user3357612
- 101
- 2
- 6
6
votes
2 answers
Signal handler won't see global variable
Here's the problem: this program should receive input from stdin and count the bytes inserted; the SIGUSR1 signal whill stop the main program and will print on file standard error how many bytes have been copied when I send the SIGUSR1.
That's how…

elmazzun
- 1,066
- 2
- 18
- 44
5
votes
4 answers
freeing memory inside a signal handler
I am writing an API that uses sockets. In the API, I allocate memory for various items. I want to make sure I close the sockets and free the memory in case there is a signal such as Ctrl-C. In researching this, it appears free() is not on the…

Mike
- 105
- 1
- 2
- 5
5
votes
2 answers
Returning from Signal Handlers
Am I not leaving my signal handler function in the correct way? It does not seem to return to the program normally. Instead it goes into the loop and where it should wait for user input, it skips and reads the length of the "user input" to -1 and…

jaiesh
- 146
- 2
- 12
5
votes
3 answers
catching signals while reading from pipe with select()
using select() with pipe - this is what I am doing and now I need to catch SIGTERM on that. how can I do it? Do I have to do it when select() returns error ( < 0 ) ?

hari
- 9,439
- 27
- 76
- 110
5
votes
1 answer
Signal handling in C++
Argument of type void (*)(int) is incompatible with parameter of type __sighnd64_t
Below is my simple code:
#include
#include
#include
#include
#include
#include
typedef struct mystrcut
{
…

Sam
- 71
- 1
- 4
5
votes
1 answer
C wait for signal with loop
In C Linux, is there any way to wait for signal like SIGUSR1 and SIGUSR2 without loop?
For eaxmple in this code I wait for SIGUSR1 or SIGUSR2 to print message, but while I want , I do while true....
#include
#include
#include…

joif doi
- 181
- 1
- 2
- 10
5
votes
4 answers
How to resolve REG_EIP undeclared (First use in this function ) error on Linux 32 bit machine?
I have been coming across errors in compilation of my signal handler program written in C language with gcc in displaying the dumped register values after occurance of Segmentation fault. When i tried to access it using the code:
void…

vlc
- 185
- 2
- 3
- 9
5
votes
1 answer
Sigsuspend equivalent to atomic series of sigprocmask, pause, sigprocmask?
I was reading my textbook's chapter (CS:APP, 3rd ed., chapter 8, page 781) on signals/ECF for Linux x86-64 systems, and came across this:
The sigsuspend function temporarily replaces the current blocked set with mask and then suspends the process…

k0zm0tis
- 69
- 2
5
votes
2 answers
Can two sequential assignment statements in C be executed on hardware out of order?
Given the following C program:
static char vals[ 2 ] = {0, 0};
int main() {
char *a = &vals[0];
char *b = &vals[1];
while( 1 ) {
SOME_STUFF()
// non-atomic operations in critical section
if( SOME_CONDITION() )
{
*a =…

leo1
- 61
- 6