04-10-2008
Works for me on both linux 2.6.x and FreeBSD 6.0-RELEASE.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
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)
Discussion started by: jalburger
2 Replies
2. Programming
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)
Discussion started by: jens
3 Replies
3. Programming
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)
Discussion started by: blowtorch
4 Replies
4. Programming
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)
Discussion started by: Tuvia
8 Replies
5. Programming
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)
Discussion started by: soeckel
2 Replies
6. Shell Programming and Scripting
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)
Discussion started by: som.nitk
2 Replies
7. Programming
Hi,
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... (6 Replies)
Discussion started by: sree_ec
6 Replies
8. Shell Programming and Scripting
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)
Discussion started by: SFNYC
1 Replies
9. Programming
i m unble to execute code of
signal handler using
a) Wait b) Waitpid (1 Reply)
Discussion started by: madhura
1 Replies
10. Programming
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 NETBSD
setitimer
GETITIMER(2) BSD System Calls Manual GETITIMER(2)
NAME
getitimer, setitimer -- get/set value of interval timer
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <sys/time.h>
int
getitimer(int which, struct itimerval *value);
int
setitimer(int which, const struct itimerval * restrict value, struct itimerval * restrict ovalue);
DESCRIPTION
The system provides each process with three interval timers, defined in <sys/time.h>. The getitimer() call returns the current value for the
timer specified in which in the structure at value. The setitimer() call sets a timer to the specified value, returning the previous value
of the timer if ovalue is not NULL.
A timer value is defined by the itimerval structure:
struct itimerval {
struct timeval it_interval; /* timer interval */
struct timeval it_value; /* current value */
};
If it_value is non-zero, it indicates the time to the next timer expiration. If it_interval is non-zero, it specifies a value to be used in
reloading it_value when the timer expires. Setting it_value to 0 disables a timer. Setting it_interval to 0 causes a timer to be disabled
after its next expiration (assuming it_value is non-zero).
The which parameter specifies the type of the timer:
ITIMER_REAL timer decrements in real time. This timer is affected by adjtime(2) and settimeofday(2). A SIGALRM signal is
delivered when this timer expires.
ITIMER_VIRTUAL timer decrements in process virtual time. It runs only when the process is executing. A SIGVTALRM signal is deliv-
ered when it expires.
ITIMER_PROF timer decrements both in process virtual time and when the system is running on behalf of the process. It is
designed to be used by interpreters in statistically profiling the execution of interpreted programs. Each time the
ITIMER_PROF timer expires, the SIGPROF signal is delivered. Because this signal may interrupt in-progress system
calls, programs using this timer must be prepared to restart interrupted system calls.
ITIMER_MONOTONIC timer decrements in monotonic time. This timer is not affected by adjtime(2) and settimeofday(2). A SIGALRM signal
is delivered when this timer expires.
Note that:
o Time values smaller than the resolution of the system clock are rounded up to this resolution (typically 10 milliseconds).
o The interaction between setitimer() and alarm(3) or sleep(3) is unspecified by the specification.
RETURN VALUES
If the calls succeed, a value of 0 is returned. If an error occurs, the value -1 is returned, and a more precise error code is placed in the
global variable errno.
ERRORS
Both functions may fail if:
[EFAULT] The value parameter specified a bad address.
[EINVAL] The which parameter was not a known timer type, or the value parameter specified a time that was too large to be handled.
SEE ALSO
gettimeofday(2), select(2), sigaction(2), itimerval(3), timeradd(3)
STANDARDS
The functions conform to IEEE Std 1003.1-2001 (``POSIX.1''). The later IEEE Std 1003.1-2008 (``POSIX.1'') revision however marked both as
obsolescent, recommending the use of timer_gettime(2) and timer_settime(2) instead.
HISTORY
The getitimer() function call appeared in 4.2BSD. The ITIMER_MONOTONIC functionality appeared in NetBSD 6.0.
BSD
October 27, 2011 BSD