Home > Articles > Open Source > Linux/UNIX/Open Source Operating Systems

Advanced Programming in the UNIX® Environment: UNIX File I/O

  • Print
  • + Share This
Learn about the traditional UNIX I/O functions. You will see how to apply these functions when using your UNIX system.
This chapter is from the book

3.1 Introduction

We'll start our discussion of the Unix system by describing the functions available for file I/O—open a file, read a file, write a file, and so on. Most Unix file I/O can be performed using only five functions: open, read, write, lseek, and close. We then examine the effect of different buffer sizes on the read and write functions.

The functions described in this chapter are often referred to as unbuffered I/O (in contrast to the standard I/O routines, which we describe in Chapter 5). The term unbuffered refers to the fact that each read or write invokes a system call in the kernel. These unbuffered I/O functions are not part of ANSI C, but are part of POSIX.1 and XPG3.

Whenever we describe the sharing of resources between multiple processes, the concept of an atomic operation becomes important. We examine this concept with regard to file I/O and the arguments to the open function. This leads to a discussion of how files are shared between multiple processes and the kernel data structures involved. Once we've described these features, we describe the dup, fcntl, and ioctl functions.

  • + Share This
  • 🔖 Save To Your Account