Sponsored Content
Full Discussion: alarm signal processing
Top Forums Programming alarm signal processing Post 302322931 by liaobert on Friday 5th of June 2009 01:39:05 AM
Old 06-05-2009
Error 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[tailpos], TASKBUFSIZ - tailpos); //do a read

when the alarm goes off, i want to check the value of "amt"

basically, i want to check to see that the read call was completed in under 10 seconds, however in a signal handler, i dont think you can pass in the value of amt. so is my approach possible to implement? or would i need to a fork a process and do it that way? I'd prefer not to do that, I ran into some problems with that approach..

here's the entirety of the function as well:

taskbufresult_t read_to_taskbuf(int fd, task_t *t)
{
unsigned headpos = (t->head % TASKBUFSIZ);
unsigned tailpos = (t->tail % TASKBUFSIZ);
ssize_t amt;

if (t->head == t->tail || headpos < tailpos)
amt = read(fd, &t->buf[tailpos], TASKBUFSIZ - tailpos);
else
amt = read(fd, &t->buf[tailpos], headpos - tailpos);

if (amt == -1 && (errno == EINTR || errno == EAGAIN
|| errno == EWOULDBLOCK))
return TBUF_AGAIN;
else if (amt == -1)
return TBUF_ERROR;
else if (amt == 0)
return TBUF_END;
else {
t->tail += amt;
return TBUF_OK;
}
}

help would be much appreciated, my TAs suck...Smilie
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Signal Processing

Hello, Can any body give example of using Unix Signals. What I want to do is I am running a sql query in a shell script I want, if sql query exceed the defined no. of seconds limit, then I would like to kill the process. I know this can be done thru Unix Signal Handling but I do not know... (8 Replies)
Discussion started by: sanjay92
8 Replies

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

3. Shell Programming and Scripting

Perl alarm signal

I am trying to write a signal to exit when a process times out. What I have come up with from poking around the web is this. #!/usr/bin/perl eval { local $SIG{ALRM} = sub { die "alarm clock restart" }; alarm 10; open(DSMADMC, "dsmadmc -se=tsmpc1 -id=XXXXX... (2 Replies)
Discussion started by: reggiej
2 Replies

4. Programming

Basic signal and alarm usage

I am trying to write a program that will; 1) Show the message "Snoozing now...zzzz" on the screen for 5 seconds 2) Then in the same position show the message "The ALARM is going off now!" for 5 seconds 3) Repeat 1) then 2) infinitely until user presses Ctrl C I can't make it work. Any hints... (17 Replies)
Discussion started by: enuenu
17 Replies

5. Shell Programming and Scripting

Script Signal Processing

I am trying to develop a script that will properly handle kill signals particularly kill -2. I have program (_progres) that properly receives the signal if I run it from the command line directly: _progres -T /tmp -p /home/mejones/signal.p -b 2>&1 & If I try to put it in a script (i.e.... (2 Replies)
Discussion started by: mejones99
2 Replies

6. Programming

Sinal-processing alarm()-function

hi programmers from all over the world, i am programming a simple program and want to deal with signals. i want to understand and work with the old signal-concept under unix, but i have a problem, hope you can help or knoew where i can get help. i use just one sig-handler, if a signal is... (1 Reply)
Discussion started by: xcoder44@gmx.de
1 Replies

7. Programming

Signal processing

We have written a deamon which have many threads. We are registering for the SIGTERM and trying to close main thread in this signal handling. Actually these are running on Mac OS X ( BSD unix). When we are unloading the deamon with command launchctl, it's sending SIGTERM signal to our process... (1 Reply)
Discussion started by: Akshay4u
1 Replies

8. Solaris

Signal Processing in unix

I've read the man page of singal(3) but I still can't quite understand what is the difference between SIGINT, SIGALRM and SIGTERM. Can someone tell me what is the behavioral difference among these 3 signals in kill command? Thanks! (2 Replies)
Discussion started by: joe228
2 Replies

9. Shell Programming and Scripting

Continue Processing after a signal is caught

Is it possible to continue after signal is caught and control goes to function specified in the trap statement? (3 Replies)
Discussion started by: Soham
3 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 02:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy