This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ed is guaranteed to receive the smallest available descriptor in the pool. When a process terminates for any reason, the kernel closes all open ﬁles, and frees their memory resources. By convention, each process created by a Unix shell begins life with three open ﬁles: standard input (descriptor 0), standard output (descriptor 1), and standard error (descriptor 2). The system header ﬁle unistd.h deﬁnes the following constants,
#define STDIN_FILENO 0 #define STDOUT_FILENO 1 #define STDERR_FILENO 2 which for clarity can be used instead of explicit descriptor values. 12.4.1 The read and write Functions
Applications perform input and output by calling the read and write functions, respectively.
#include <unistd.h> ssize t read(int fd, void *buf, size t count);
returns: number of bytes read if OK, 0 on EOF, -1 on error ssize t write(int fd, const void *buf, size t count);
returns: number of bytes written if OK, -1 on error The read function copies at most count bytes from the current ﬁle position of descri...
View Full Document