Chapter1 Introduction
Chapter1 Introduction
Chapter1
Topics
1.1. Introduction
1.2. UNIX Architecture
1.3. Logging In
1.4. Files and Directories
1.5. Input and Output
1.6. Programs and Processes
1.7. Error Handling
1.8. User Identification
1.9. Signals
1.10. Time Values
1.11. System Calls and Library Functions
1.12. Summary
1.13. Exercises
Questions!!!!
What is an operating system?
Different types of operating system
Single-user, single task
Single-user, multi-tasking
Multi-user
Real-time operating system(RTOS)
Single-user, multi-tasking
This is the type of operating system most people use on
Multi-user
A multi-user operating system allows many different users to take
Netware. The network support and all of the remote user logins the
network enables are, in the overall plan of the operating system, a
program being run by the administrative user.
1.1 Introduction
What is the function of an OS?
All operating systems provide services for programs they run.
Typical services include executing a new program, opening a file,
reading a file, allocating a region of memory, getting the current
time of day, and so on.
All these services are provided by the UNIX.
software called the system calls (the shaded portion in Figure 1.1).
A system call is how a program requests a service from an
operating system's kernel.
This may include hardware-related services (for example,
accessing a hard disk drive), creation and execution of new
processes, and communication with integral kernel services such
as process scheduling. System calls provide an essential interface
between a process and the operating system.
the system call interface, but applications are free to use both.
The shell: It is a special application that provides an interface for
Versions of UNIX
BSD 4.4
SunOS
Solaris
SCO UNIX
AIX
HP/UX
ULTRIX
1.3 Logging In
Login Name & password.
Password file : /etc/passwd.
If we look at our entry in the password file we see that it's composed of
sar:x:205:105:Stephen Rago:/home/sar:/bin/ksh
In Chapter 6, we'll look at these files and some functions to access
them.
Shells
Once we log in, some system information messages are
The system knows which shell to execute for us from the final field in our
entry in the password file.
C Shell
This shell was written at the University of California, Berkeley. It
provides a C-like language with which to write shell scripts hence its name.
Example:
shell prompt : %
executable file : /bin/csh
Read on csh shell invocation .
/etc/csh.cshrc
~/.cshrc
/etc/.login
~/.login
~/.logout
/etc/csh.login
interactive shell.
Example:
shell prompt : $
TC shell (tcsh)
This shell is available in the public domain. It provides all the features of
the C shell together with emacs style editing of the command line.
The default user shell in FreeBSD and Mac OS X is the TENEX C shell,
but they use the Bourne shell for their administrative shell scripts
because the C shell's programming language is notoriously difficult to
use.
Example:
shell prompt : &
executable file : /bin/tcsh
Read on tcsh shell invocation .
~/.tcshrc
/etc/csh.cshrc
~/.cshrc
Read on interactive/non interactive login to tcsh shell
/etc/.login
~/.login
~/.logout
/etc/csh.login
single character /.
A directory is a file that contains directory entries.
directory entry = filename + the attributes of the file.
The attributes of a file are:
Filename
The names in a directory are called filenames.
The only two characters that cannot appear in a filename are the slash
Pathname
A sequence of one or more filenames, separated by slashes and
The name for the root of the file system (/) is a special-case
Example
Listing the names of all the files in a directory
Working Directory
Every process has a working directory, sometimes called the
or directory lint in the directory lib, in the directory usr, which is in the
root directory.
Home Directory
When we log in, the working directory is set to our home directory.
Standard I/O
The standard I/O functions provide a buffered interface to the
bytes.
The standard I/O library provides functions that let us control the
Process Control
There are three primary functions for process control: fork, exec, and waitpid.
A thread is a flow of execution through the process code, with its own
multiprocessor systems.
Each thread belongs to exactly one process and no thread can exist outside
a process.
As with processes, threads are identified by IDs. Thread IDs, however, are
local to a process.
A thread ID from one process has no meaning in another process.
We use thread IDs to refer to specific threads as we manipulate the threads
within a process.
Threads
Multitasking
Multiprocessing
Multithreading
Multithreading extends the idea of multitasking into applications, so you can
Error Recovery
The errors defined in <errno.h> can be divided into two
Group ID
Assigned by the system administrator when our login
name is assigned.
Groups are normally used to collect users together into
projects or departments. This allows the sharing of
resources, such as files, among members of the same
group.
There is also a group file that maps group names into
numeric group IDs. The group file is usually /etc/group.
With every file on disk, the file system stores both the user
ID and the group ID of a file's owner
Storing both of these values requires only four bytes,
assuming that each is stored as a two-byte integer.
getuid(), getgid(); from "apue.h"
1.9. Signals
Signals are a technique used to notify a process that some
Signals
Many conditions generate signals.
Two terminal keys, called the interrupt key often the DELETE key
Time Values
When we measure the execution time of a process, the
Clock time
The clock time, sometimes called wall clock time, is the amount of
time the process takes to run
Its value depends on the number of other processes being run on
the system.
Time Values
The user CPU time
is the CPU time attributed to user instructions.
The system CPU time
is the CPU time attributed to the kernel when it executes on behalf
of the process.
For example, whenever a process executes a system service, such
as read or write, the time spent within the kernel performing that
system service is charged to the process.
The sum of user CPU time and system CPU time is often called the
CPU time.
to output a string,
but the strcpy (copy a string) and atoi (convert ASCII to integer)
functions don't involve the kernel at all.
Both system calls and library functions appear as normal C
functions.
Both exist to provide services for application programs.
We should realize, however, that we can replace the library
functions, if desired, whereas the system calls usually cannot
be replaced.
Example:
Malloc uses sbrk system call
We can change the implementation of malloc using sbrk system call.