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
amt(1)								   User Commands							    amt(1)

NAME
amt - run abstract machine test SYNOPSIS
amt [-s] DESCRIPTION
The amt command is for use in a Common Criteria security certified system. The command is used to verify that the low level functions nec- essary to enforce the object reuse requirements of the Controlled Access Protection Profile are working correctly. /usr/bin/amt is a shell script that executes tests specific to your system. For a 32-bit system, the tests run as a 32-bit application. For a 64-bit system, the tests run twice; once as a 32-bit application and once as a 64-bit application. amt lists test results with a "pass" or "fail" for each test it performs, unless output is suppressed with the -s option. OPTIONS
The following option is supported: -s Suppresses output. EXIT STATUS
The following error values are returned: 0 All tests passed. >0 Count of the number of tests that failed. <0 Incorrect command line argument. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5) SunOS 5.10 19 Aug 2003 amt(1)
All times are GMT -4. The time now is 03:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy