The focus of this text is to describe the services provided by various versions of the UNIX operating system.

    In a strict sense, an operating system can be defined as the software that controls the hardware resources of the computer and provides an environment under which programs can run. Generally, we call this software kernel.
    IMG_0151 copy.jpg

    The shell may also call library routines ?

    In a broad sense, an operating system consists of the kernel and all the other software that makes a computer useful and gives the computer its personality. This other software includes system utilities, applications, shells, libraries of common functions, and so on.

    The UNIX file system is a hierarchical arrangement of directories and files. A directory is a file that contains directory entries. Logically, we can think of each directory entry as containing a file name along with a structure of information describing the attributes of the file.

    Manual are divided into sections. e.g. man -s1 du

    The standard I/O functions provide a buffered interface to the unbuffered I/O functions.

    An executing instance of a program is called a process. Some operating systems use the term task.

    All threads within a process share the same address space, file descriptors, stacks and process-related attributes. Each thread executes on its own stack, although any thread can access the stacks of other threads in the same process.

    Error Handling
    When an error occurs in one of the UNIX System functions, a negative value is often returned, and the integer errno is ususally set to a value that tells why. Some functions use a convertion other than returning a negative value. For example, most functions that return a pointer to an object return a null pointer to indicate an error.

    POSIX and ISO C define errno as a symbol expanding into a modifiable lvalue of type integer. This can be either an integer that contains the error number or a function that returns a pointer to the error number. The historical definition is

    1. extern int errno;

    But in environment that supports threads, the process address space is shared among multiple threads, and each thread needs its own local copy of errno to prevent one thread from interfering with another. Linux, for example, supports multithreaded access to errno by defining it as

    1. extern int *__errno_location(void);
    2. #define errno (*__errno_location())

    There are two rules to be aware of with respect to errno .

    • First, its value is never cleared by a routine if an error does not occur. Therefore, we should examine its value only when the return value from a function indicates that an error occurred.
    • Second, the value of errno is never set to 0 by any of the functions, and none of the constants defined in <errno.h> has a value 0.

    The errors defined in <errno.h> can be divided into two categories: fatal and nonfatal. The typical recovery action for a resource-related nonfatal error is to delay and retry later. Ultimately, it is up to the application developer to determine the cases where an application can recover from an error.

    User ID, Group ID, Supplementary Group ID

    Signals are a technique used to notify a process that some condition has occurred. The process has three choices for dealing with the signal.

    Historically, UNIX systems have maintained two different time values:

    1. Calendar time: data type is time_t
    2. Process time (also called CPU time): measures the central processor resources used by a process. data type is clock_t

    When we measure the execution time of a process, we’ll see that the UNIX System maintains three values for a process:

    • Clock time
    • User CPU time
    • System CPU time

    The system call interface has always been documented in Section 2 of the UNIX Programmer’s Manual. Its definition is in the C language, no matter which implementation technique is actually used on any given system to invoke a system call.

    The technique used on UNIX systems is for each system call to have a function of the same name in the standard C library. The user process calls this function, using the standard C calling sequence. This function then invokes the appropriate kernel service, using whatever technique is required on the system. For example, the function may put one or more of the C arguments into general registers and then execute some machine instruction that generates a software interrupt in the kernel. For out purposes, we can consider system calls to be C functions.

    Section 3 of the UNIX programmer’s Manual defines the general-purpose library functions available to programmer. These functions aren’t entry points into the kernel, although they may invoke one or more of the kernel’s system calls.
    IMG_0153 copy.jpg
    In this text, we’ll use the term funciton to refer to both system calls and library functions, except when distinction is necessary.