Sponsored Content
Top Forums Programming Problem with signal handler and interrupted system call Post 302280302 by otheus on Monday 26th of January 2009 12:45:58 PM
Old 01-26-2009
Quote:
Code:
       retval = read(fd, &data, sizeof(unsigned long));
        if (retval == -1) {
            perror("read");
            exit(errno);
        }

That's your problem, more or less. If read() is interrupted by a system call, it returns -1, sets errno to EINTR. Your program itself does the perror and exiting, not read(). So just check if the return is -1 and errno != EINTR and restart the loop (for instance). You'll have to handle the logic for the ioctls and what not, too, or every now and then, your signal will interrupt the ioctl and exit.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script signal handler

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

sigwait system call in UNIX signal

Hi Everybody, I have gone through man of sigwait and new to UNIX signals. Could anyone explain me about the following lines mentioned in sigwait man help ? "The selection of a signal in set is independent of the signal mask of the calling thread or LWP. This means a thread or LWP can ... (1 Reply)
Discussion started by: md7ahuja
1 Replies

3. Programming

signal handler for SIGCHLD

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

4. Programming

signal handler problems

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

5. Programming

Runaway SIGALRM signal handler

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)
Discussion started by: stewartw
8 Replies

6. Shell Programming and Scripting

Perl - Problems with Signal Handler

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

Signal Handler Hangs

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

Perl Signal Handler

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

problem in doing coding of signal handler

i m unble to execute code of signal handler using a) Wait b) Waitpid (1 Reply)
Discussion started by: madhura
1 Replies

10. Programming

Serial port signal(IRQ) handler (using C)

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
siginterrupt(3) 					     Library Functions Manual						   siginterrupt(3)

Name
       siginterrupt - allow signals to interrupt system calls

Syntax
       siginterrupt(sig, flag)
       int sig, flag;

Description
       The  system call is used to change the system call restart behavior when a system call is interrupted by the specified signal.  If the flag
       is false (0), then system calls will be restarted if they are interrupted by the specified signal and no data  has  been  transferred  yet.
       System call restart is the default behavior on 4.2 BSD.

       If  the flag is true (1), then restarting of system calls is disabled.  If a system call is interrupted by the specified signal and no data
       has been transferred, the system call will return -1 with errno set to EINTR.  Interrupted system calls that have started transferring data
       will  return the amount of data actually transferred.  System call interrupt is the signal behavior found on 4.1 BSD and AT&T System V sys-
       tems.

       Note that the new signal handling semantics are not altered in any other way.  Most notably, signal handlers always remain installed  until
       explicitly  changed  by a subsequent call, and the signal mask operates as documented in Programs may switch between restartable and inter-
       ruptible system call operation as often as desired in the execution of a program.

       Issuing a call during the execution of a signal handler will cause the new action to take place on the next signal to be caught.

Environment
       This library routine uses an extension of the system call that is not available in ULTRIX 2.0 or earlier versions.  Hence it should not	be
       used if backward compatibility is needed.

Return Values
       A 0 value indicates that the call succeeded.  A -1 value indicates that an invalid signal number has been supplied.

See Also
       sigvec(2), sigblock(2), sigpause(2), sigsetmask(2)

4.3 Berkeley Distribution													   siginterrupt(3)
All times are GMT -4. The time now is 07:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy