Open System Services System Calls Reference Manual (G06.28+)
write(2) OSS System Calls Reference Manual
• If the size of the write() request is less than or equal to the value of the PIPE_BUF sys-
tem variable, the write() function is guaranteed to be atomic. The data is not interleaved
with data from other processes doing writes on the same pipe.
• If the size of the write() request is greater than the value of the PIPE_BUF system vari-
able, the file system attempts to resize the pipe buffer from 2 * PIPE_BUF to 65,536
bytes. If the resizing is successful, the file system performs atomic writes of up to 32,768
bytes and can transfer up to 52 kilobytes of data from the pipe buffer on subsequent
read() or readv() calls by the client.
If the file system cannot resize the buffer, it continues to use the existing buffer. A
second attempt at resizing occurs after approximately a minute elapses.
Writes of greater than PIPE_BUF bytes can have data interleaved, on arbitrary boun-
daries, with writes by other processes, whether or not the O_NONBLOCK flag is set.
• If the O_NONBLOCK flag is not set, a write() request to a full pipe causes the process
to block until enough space becomes available to handle the entire request.
• If the O_NONBLOCK flag is set, write( ) requests are handled differently in these ways:
— The write() function does block the process.
— write() requests for PIPE_BUF or fewer bytes either succeed completely and
return the value of the nbytes parameter, or return the value -1 and set errno to
[EAGAIN].
— A write( ) request for greater than PIPE_BUF bytes either transfers what it can
and returns the number of bytes written, or transfers no data and returns the value
-1 with errno set to [EAGAIN]. Also, if a request is greater than PIPE_BUF
bytes and all data previously written to the pipe has been read, write() transfers
at least PIPE_BUF bytes.
When attempting to write to a file descriptor for a special character device (a terminal) that can-
not accept data immediately:
• If the O_NONBLOCK flag is clear, the write() function blocks until the data can be
accepted or an error occurs.
• If the O_NONBLOCK flag is set, the write() function returns the value -1 and errno is
set to [EAGAIN].
When attempting to write to a socket and with no space available for data:
• If the O_NONBLOCK flag is not set, the write() function blocks until space becomes
available or an error occurs.
• If the O_NONBLOCK flag is set, the write() function returns the value -1 and sets
errno to [EWOULDBLOCK].
Upon successful completion, the write() function marks the st_ctime and st_mtime fields of the
file for update and clears the set-user-ID and set-group-ID attributes if the file is a regular file.
The fcntl() function provides more information about record locks.
If it is interrupted by a signal before it writes any data, the write() function returns the value -1
with errno set to [EINTR]. If it is interrupted by a signal after it has successfully written some
data, the write() function returns the number of bytes that it has written.
10−14 Hewlett-Packard Company 527186-005