Technology

Book Notes

Operating Systems: Processes and Files

August 24, 2024

The Role of Files and Processes for the OS

(Notes from "Operating Systems: Design and Implementation," by Andrew S. Tanenbaum and Albert S. Woodhull).

The operating system provides a virtual interface for the user to program the underlying hardware. It manages and simplifies all the pieces of a complex system, keeping track of who is using resources, accounting for usage and mediating conflicting requests.

The OS provides the user with a set of “extended instructions,” or system calls, which can be implemented in multiple ways. Some deal with processes, and others deal with file systems.

A process is a program being executed. Each process has an address space, a dedicated portion of the system’s memory with full read and write access for the program to use.

Into this memory space, the computer puts the program code, its data and the stack, which is a list of upcoming instructions for the computer to execute.

To run the program, the computer also provides a set of registers, which keep track of the program counter, stack pointer and any associated hardware registers.

This is important because the OS may at any time stop working on a particular program to work on another program, perhaps one of higher priority.

All the program's registry pointers, then, are stored in a process table, an array of all processes currently running, so the OS can pick it up again.

When a program finishes, it typically executes a system call to terminate itself. A process can also create other processes, called child processes.

Files are the abstraction used to hide, or abstract away, the low-level functions of disk drives (and other I/O devices). An OS has a set of system calls to read, write, create and remove files.

An OS uses the concept of directories to manage files. Like processes, files are managed as trees, with a parent element controlling a child one. The top of the hierarchy is the root directory and any file’s location is identified through the path of directories, i.e documents//writing/music .

Each process has a working directory, where it can find the files it needs.

In order to protect files and directories from being accessed by inappropriate users, each file and directory is given a binary protection code.

In Unix, this is a series of 9 numbers (“9 bit”), consisting of three 3-bit fields. One is a set of permissions for the owner, one is a set for a group, should the file need to be accessed by multiple entities, and the final field is for everyone else.

Within each three bit field are designators for read (“r”), write (“w”) and access or search (“x”) permissions. If the user has these codes, it means they are granted the corresponding access.

So rwxr-x–x means the owner can read, write and search the file, while others in the group can read and search but not write the file, and everyone else can search the file but have no read or write privileges.

More about how permissions work in Linux can be found here.

To mount additional directories onto the file structure tree, such as from a USB drive, use the MOUNT system call. The new file system is mounted to the root file system at the specified location.

External devices, such as printers, are also mounted through the file system, via block and character-based special files. These files can be read and written with the same system calls, and they can input and output character streams.

A pseudo file, called a pipe, can connect different processes together, so that the output of one process serves as the input or another.

Back