interrupted system call

interrupted system call

Post by aha.. » Sun, 05 Jul 1992 03:26:25



Consider the following codes:

catch()
{
        signal(SIGINT, catch);
        printf("SIGINT occurs\n");

Quote:}

main()
{
        signal(SIGINT, catch);

        for ( ; ; ) {

                read(fd, buf, buflen);

                ....

        }

Quote:}

Suppose the program is doing a read (blocking) and SIGINT occurs.
'read' is interrupted and control goes to the signal-handler ('catch');
After that, read will be restarted again (suppose the unix supports it).
My question is: if the interrupted read operation was in the middle of
reading some data, would the restarted 'read' maintain this data? Is there
a possibility of losing some of the bytes between the point where 'read'
started reading and the SIGINT occured?

Thanks
/aha

 
 
 

interrupted system call

Post by Larry Jon » Tue, 07 Jul 1992 04:22:39



> Suppose the program is doing a read (blocking) and SIGINT occurs.
> 'read' is interrupted and control goes to the signal-handler ('catch');
> After that, read will be restarted again (suppose the unix supports it).
> My question is: if the interrupted read operation was in the middle of
> reading some data, would the restarted 'read' maintain this data? Is there
> a possibility of losing some of the bytes between the point where 'read'
> started reading and the SIGINT occured?

On those unices that restart interrupted system calls, the system call is
restarted only if it has not already begun to tranfer data.  If it has
started to transfer data, it will not be restarted and will return the
amount of data transferred (which may well be less than you requested).
On unices that don't restart, the system call should return -1 with errno
set to EINTR if no data had been transferred or the amount of data that
had been transferred.  Unfortunately, at least some systems are broken
and return -1/EINTR even when data had already been transferred.  (Does
anyone know exactly which systems behave this way?  I know for sure that
IBM's AIX 3.1 does if you don't enable system call restarts.)
----
Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH  45150-2789  513-576-2070

I take it there's no qualifying exam to be a Dad. -- Calvin