help needed on a unix system-call question

Kenneth Almquist ka at june.cs.washington.edu
Sat Mar 11 05:31:55 AEST 1989


guy at auspex.UUCP (Guy Harris) writes:
> Assuming by "is it possible to lose the partially read data" you mean
> "if the 'read' blocks, and then transfers some data and blocks waiting
> for more data, and *then* gets interrupted by a signal, is the data it
> transferred more-or-less lost", the answer is "yes, and this happens
> under 4.xBSD as well".  The problem is that, since you get a -1 back
> from the "read", rather than a count of the number of bytes read, you
> have no idea how much data was actually transferred. 

I don't know of any cases where this should happen, at least on System V.
Reads on regular files, directories, disk devices and magnetic tapes are
not interruptable (assuming that the disk and tape device drivers don't do
nonstandard things).  Reads on a pipe will block until the pipe is nonempty
and then transfer what is in the pipe, so if a read on a pipe can only be
interrupted before any data is transferred.  Reads on cooked tty devices
block until an entire line is available and then copy in the entire line at
once.  I don't remember the raw tty device code as well, but I'm pretty
sure that in this case as well all the characters are buffered inside the
kernel and transferred to the user space in an uninterruptable operation
right before the read returns.

Write operations on a tty are different, since it is possible to write
more characters than the kernel is willing to buffer internally.  If the
write system call is interrupted after some but not all of the data has
been written, the kernel will return the number of characters written
rather than returning an error indication, so you can write out the rest
of the characters later.
				Kenneth Almquist



More information about the Comp.unix.wizards mailing list