Sponsored Content
Top Forums Programming Sinal-processing alarm()-function Post 302283445 by otheus on Tuesday 3rd of February 2009 11:00:11 AM
Old 02-03-2009
Hopefully, 1 month delay is not too long for an answer:

The main thing is this: just before a signal handler is called, subsequent signals on that same signal are blocked. The return function from a signal handler is "special" in that it unblocks that mask. I'm not sure where this is documented, but you can demonstrated it by adding a couple of printf("%x\n",siggetmask()); calls, in the signal handler, and right after the alarm() call. But because your signal handler does a longjmp instead of a return, the signal mask never gets reset.

Or, to do it "by hand", you can do this in your signal handler (or on return from it):
Code:
    sigset_t sigset;
    sigfillset(&sigset);
    sigprocmask(SIG_UNBLOCK,&sigset,NULL);

All you need to do is set savemask=1 when you declare it. Then things will work the way you intended. This tells the setlongjmp() call to restore the original signal mask when it does the jump -- in effect, emulating the normal return-from-signal code.

There is also a problem mixing SIGALRM and wait(). From the wait(3) man page:
Code:
BUGS
       sleep()  may  be implemented using SIGALRM; mixing calls to alarm() and
       sleep() is a bad idea.

       Using longjmp() from a signal handler  or  modifying  the  handling  of
       SIGALRM while sleeping will cause undefined results.


Last edited by otheus; 02-03-2009 at 12:03 PM.. Reason: added sigprocmask()
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Alarm signal

Hi, when I execute a script on unix AIX, I've got an error message: "Execution: 85328 Signal d'alarme". If I edit this file with "vi", I ve got the same error after a while (about 1 minute). If I try with another user I still have the problem. But if I rename this file, no problem. My... (5 Replies)
Discussion started by: cgsteph
5 Replies

2. UNIX for Dummies Questions & Answers

alarm

Hello I have a server HP ES40 with unix 5.1B, and if i open from Start-Programs-IN Tools-GUI/pfmalarm/Alarm-start monitoring , I receive this error message "IOR : STRING IS TOO LONG ! MAXIMUM SIZE = 1024" Anybody heard about this error? Thanks Alin (0 Replies)
Discussion started by: tomaalin
0 Replies

3. AIX

File Accessed Alarm ??

Hey, I want to ask a simple Question.... How would I be able to come to know that files/directoires in a Parent directory has been accessed (means contents of the file has been just viewed) by the user(s) in a group ? and mail the name(s) of those files/directories which has been accessed... (1 Reply)
Discussion started by: varungupta
1 Replies

4. Shell Programming and Scripting

File Accessed Alarm ??

Hey, I want to ask a simple Question.... How would I be able to come to know that files/directoires in a Parent directory has been accessed (means contents of the file has been just viewed) by the user(s) in a group ? and mail the name(s) of those files/directories which has been accessed... (16 Replies)
Discussion started by: varungupta
16 Replies

5. Shell Programming and Scripting

raise an alarm in Unix

Hi members, I am working in WebSphere in Unix environment. we are working with 500 odd servers and most of the times processes got down. Can i have any shell script through whih some popup with alarm get raised whenever some server get down. kindly help.. Thanks Rishi (1 Reply)
Discussion started by: rishi.madan
1 Replies

6. Programming

alarm signal processing

I'm writing a function right now, and I want to set an alarm to avoid a timeout, here's the general idea of my code: int amt = -2; alarm(10); amt = read(fd, &t->buf, TASKBUFSIZ - tailpos); //do a read when the alarm goes off, i want to check the value of "amt" ... (1 Reply)
Discussion started by: liaobert
1 Replies

7. Shell Programming and Scripting

Scripting an alarm

Hi All, I am monitoring batch Processes running in UNIX environment. I use PuTTy to monitor the process running. I have to continuously monitor and look on the screen if some error has come or not. If an error comes FAILURE word is displayed instead of SUCCESS as shown below on the... (2 Replies)
Discussion started by: sampandey31
2 Replies

8. What is on Your Mind?

Alarm interrupt and multithreading

Hi Friends any know how became a friend in this Android Programming Language (0 Replies)
Discussion started by: ljarun
0 Replies

9. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

10. Shell Programming and Scripting

Bash to goto specific line/function and start processing if user response is yes

In the bash below I am trying to run the script entire script including the ....(which is a bunch of code) and then in the run function if the user response is y (line in bold). then start processing from execute function. Basically, goto the # extract folder for variable filename line and start... (4 Replies)
Discussion started by: cmccabe
4 Replies
alarm(3)						     Library Functions Manual							  alarm(3)

NAME
alarm, ualarm - Sets or changes the timeout of interval timers. LIBRARY
Standard C Library (libc) SYNOPSIS
#include <unistd.h> unsigned int alarm( unsigned int seconds); useconds_t ualarm( useconds_t useconds, useconds_t interval); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: alarm(), ualarm(): XSH5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies a number of real-time seconds. Specifies a number of real-time microseconds. Specifies the interval for repeating the timer. DESCRIPTION
The alarm() function is used to obtain notification of a timeout after the number of real-time seconds specified by the seconds parameter has elapsed. At some time after seconds seconds have elapsed, a signal is delivered to the process. Each call resets the timer to the new value. A value of 0 (zero) disables the timer. When the notification signal is caught or ignored, no action takes place; otherwise the calling process is terminated. The alarm() function uses the ITIMER_REAL interval timer. The ualarm() function is used to obtain notification of a timeout after the number of real-time microseconds specified by the useconds parameter has elapsed. When the interval parameter is nonzero, timeout notification occurs after the number of microseconds specified by the interval parameter has been added to the useconds parameter. When the notification signal is caught or ignored, no action takes place; otherwise the calling process is terminated. The ualarm() function is the simplified interface to the setitimer() function, and uses the ITIMER_REAL interval timer. NOTES
The alarm() and ualarm() functions are supported for multithreaded applications. Although the alarm() and ualarm() functions are reentrant, it should be noted that just as the second of two calls from a single thread to alarm() resets the timer, this is also true if two calls are made from different threads. RETURN VALUES
If there is a previous alarm() request with time remaining, the alarm() function returns a non-zero value that is the number of seconds until the previous request would have generated a SIGALRM signal. Otherwise, alarm() returns 0 (zero). The ualarm() function returns the number of microseconds remaining from the previous ualarm() call. If no timeouts are pending or if ualarm() has not previously been called, ualarm() returns 0 (zero). ERRORS
The alarm() function sets errno to the specified values for the following conditions: [Tru64 UNIX] The seconds parameter specifies a value greater than 100,000,000. RELATED INFORMATION
Functions: gettimer(3) Standards: standards(5) delim off alarm(3)
All times are GMT -4. The time now is 04:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy