I have a problem with signal handler algorithm in linux. My code is hanging ( It is continuously looping inside the signal handler) . I am pasting my code here...
Please provide me some help regarding this. I googled many places and wrote this code.. but doesnt seem to be working without exit(0).. but i guess this is not the right way. What could be wrong?
AIX 4.3.3
I am trying to write a signal handler into a ksh shell script. I would like to capture the SIGTERM, SIGINT, and the SIGTSTP signals, print out a message to the terminal, and continue executing the script. I have found a way to block the signals:
#! /bin/ksh
SIGTERM=15
SIGINT=2... (2 Replies)
Hi,
I have an c++ application which uses the function fork and execvp().
The parent does not wait until the child ends. The parents just creates children and let them do their stuff.
You can see the parent program as a batch-manager.
I have added a SIGCHLD handler to the program:
void... (3 Replies)
Hey guys,
I am trying to write a little shell, and was writing a signal handler to handle SIGINT (I am using 'stty intr ^C' and using ctrl-C to give SIGINT).
I wrote this signal handler: void handle_sigint()
{
write(2,"handling sigint\n",16);
write(1,"\nshell% ",8);
}
... (4 Replies)
I have written a program to demonstrate a problem I have encountered when using BSD style asynchronous input using the O_ASYNC flag in conjunction with a real time interval timer sending regular SIGALRM signals to the program. The SIGIO handler obeys all safe practices, using only an atomic update... (8 Replies)
Is it ok to use exit() inside a signal handler?
I catch SIGUSR1 in a signal handler and I try to close a file and then exit. The result is inconsistent. Sometimes the process exit and sometimes it returns to the original state before the signal handler was invoked.
Perhaps exit is not legal in... (8 Replies)
Hi,
I have a daq program that runs in an infinite loop until it receives SIGINT. A handler catches the signal and sets a flag to stop the while loop. After the loop some things have to be cleaned up.
The problem is that I want my main while loop to wait until the next full second begins, to... (2 Replies)
I have a problem with signal handlers not working.
I have a long 1000 line code and somehow this code for signal handling is not working:
$SIG{INT} = \&interrupt;
sub interrupt {
print STDERR "Caught a control c!\n";
exit; # or just about anything else you'd want to do
}
Any... (2 Replies)
I was working on some Perl code that does signal handling and I came across this one liner and wasn't sure what it was doing.
local $SIG{__DIE__} = sub {$! = 2; die $_;};
I think the first part of the anonymous subroutine is setting $! to 2, but I am not sure what the second part is doing. ... (1 Reply)
Hello,
I'm writing some serial(UART) handler but have stuck on few issues, maybe anyone can help to show me what I'm doing wrong.
Basically I'm intending to write serial RX signal handler.
Application receives defined packages of data over serial which contains header and payload. Handler... (3 Replies)
Discussion started by: Lauris_k
3 Replies
LEARN ABOUT OPENSOLARIS
stack_violation
stack_violation(3C) Standard C Library Functions stack_violation(3C)NAME
stack_violation - determine stack boundary violation event
SYNOPSIS
#include <ucontext.h>
int stack_violation(int sig, const siginfo_t *sip,
const ucontext_t *ucp);
DESCRIPTION
The stack_violation() function returns a boolean value indicating whether the signal, sig, and accompanying signal information, sip, and
saved context, ucp, represent a stack boundary violation event or a stack overflow.
RETURN VALUES
The stack_violation() function returns 0 if the signal does not represent a stack boundary violation event and 1 if the signal does repre-
sent a stack boundary violation event.
ERRORS
No errors are defined.
EXAMPLES
Example 1 Set up a signal handler to run on an alternate stack.
The following example sets up a signal handler for SIGSEGV to run on an alternate signal stack. For each signal it handles, the handler
emits a message to indicate if the signal was produced due to a stack boundary violation.
#include <stdlib.h>
#include <unistd.h>
#include <ucontext.h>
#include <signal.h>
static void
handler(int sig, siginfo_t *sip, void *p)
{
ucontext_t *ucp = p;
const char *str;
if (stack_violation(sig, sip, ucp))
str = "stack violation.
";
else
str = "no stack violation.
";
(void) write(STDERR_FILENO, str, strlen(str));
exit(1);
}
int
main(int argc, char **argv)
{
struct sigaction sa;
stack_t altstack;
altstack.ss_size = SIGSTKSZ;
altstack.ss_sp = malloc(SIGSTKSZ);
altstack.ss_flags = 0;
(void) sigaltstack(&altstack, NULL);
sa.sa_sigaction = handler;
(void) sigfillset(&sa.sa_mask);
sa.sa_flags = SA_ONSTACK | SA_SIGINFO;
(void) sigaction(SIGSEGV, &sa, NULL);
/*
* The application is now set up to use stack_violation(3C).
*/
return(0);
}
USAGE
An application typically uses stack_violation() in a signal handler that has been installed for SIGSEGV using sigaction(2) with the SA_SIG-
INFO flag set and is configured to run on an alternate signal stack.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Evolving |
+-----------------------------+-----------------------------+
|MT-Level |Async-Signal-Safe |
+-----------------------------+-----------------------------+
SEE ALSO sigaction(2), sigaltstack(2), stack_getbounds(3C), stack_inbounds(3C), stack_setbounds(3C), attributes(5)SunOS 5.11 18 Jul 2002 stack_violation(3C)