You are on page 1of 39

O.S. by Er. K.S.

Dhindsa © 2007

CASE STUDY – UNIX

Lecture Series By :

Er. Kanwalvir Singh Dhindsa

Deptt. of CSE & IT

www.dhindsa.info

1
UNIX -- HISTORY
◆ AT&T
Ritchie & Thompson’s “Unics”
{Uniplexed Operating & Computing system}
• 1965 – Bell and GE joined project MAC at MIT to develop
Multics.
• Goal: Multicomputing and data sharing for a large group
of users.
 YEAR - 1969
Thompson and Ken Ritchie implemented an earlier
designed file system on PDP-7.
This grew into UNIX.
File system design and idea of command interpreter
(shell) as a user process came from MULTICS
Fork idea came from Berkeley’s GENIE OS. 2
O.S. by Er. K.S.Dhindsa © 2007
UNIX -- HISTORY

 1971 – UNIX used in first real project: text processing


for BELL labs patent department
 1971 – UNIX required 16K bytes for system, 8K bytes
for user programs, 512K bytes of disk, and limit of 64K disk
bytes per file.
Thompson set out to write a new Fortran compiler but
developed a new programming language: B. B was based
on BCPL (a tool for compiler writing and systems
programming). He later improved on B and called it C
1973 – UNIX rewrittten in C (unheard of at the time)
 AT&T offered UNIX free to universities

3
O.S. by Er. K.S.Dhindsa © 2007
UNIX -- HISTORY

1982 – First external distribution from USG – System III


UC Berkeley developed their version of UNIX (Berkeley
software Distributions).
 BSD introduced vi in 2BSD, demand-pages virtual
memory in 3BSD, TCP/IP networking protocol in 4.2BSD.
 Less than 3% of BSD written in assembly.

 YEAR 1991 – Finnish student Linus Torvalds wrote


Linux for 80386, 32 bit processor

4
O.S. by Er. K.S.Dhindsa © 2007
BSD Layer Structure

5
O.S. by Er. K.S.Dhindsa © 2007
SYSTEM CALL & FILE MANIPULATION

Three categories of system calls in UNIX :

 File manipulation (same system calls also support


device manipulation)
Process control & Information manipulation.
• A file is a sequence of bytes; the kernel does not impose a
structure on files.
• Files are organized in tree-structured directories
• Path name: identifies a file by specifying a path through the
directory structure to the file.
– Absolute path names start at root of file system
– Relative path names start at the current directory
• System calls for basic file manipulation: create, open, read, write,
6
close, unlink, trunc.
O.S. by Er. K.S.Dhindsa © 2007
UNIX DIRECTORY STRUCTURE

7
O.S. by Er. K.S.Dhindsa © 2007
Design Philosophy

• Simplicity
• C language
• Time-sharing
• Simple user interface (modular and may be
replaced)
• Device independence (treat files and devices
in same manner)
• Aimed for programming environment
• Flexibility

8
O.S. by Er. K.S.Dhindsa © 2007
UNIX - Design Principles

• Designed to be a time-sharing system.


• Has a simple standard user interface (shell) that can
be replaced.
• File system with multilevel tree-structured directories.
• Files are supported by the kernel as unstructured
sequences of bytes.
• Supports multiple processes; a process can easily
create new processes.
• High priority given to making system interactive, and
providing facilities for program development.
9
O.S. by Er. K.S.Dhindsa © 2007
Absolute & Relative Paths

• A pathname (or path) is a route from the


root to the file or directory in question
• Directory names are separated by /’s
• A path beginning with a / is an absolute
path
• What is a relative path ?????

10
O.S. by Er. K.S.Dhindsa © 2007
SHELL
•Programs such as shell and vi interact with kernel using
well defined system call procedures.
 Most of what is considered the Unix
interface is really the SHELL INTERFACE
◆ The shell is equivalent to COMMAND.COM on DOS
• sh the Bourne shell (after its creator)
• ksh the Korn Shell: sh plus visual editing
• csh the C-shell: introduced C-style programming
features
• tcsh: csh plus visual editing
• bash the Bourne Again SHell: sh plus visual editing
11
O.S. by Er. K.S.Dhindsa © 2007
Role of SHELLS

• Shells provide:
– Multiple commands on a single line
– Redirection of input and output (like >>)
– Expansion of wildcard filenames
– Background execution
– Pipelines
– Script-programming facility
• Normally the shell waits for a command to complete
before prompting for another command
• Can run a job in the background and not wait for it
12
O.S. by Er. K.S.Dhindsa © 2007
PROCESS MANAGEMENT

• Process is program in execution


• Consists of machine instructions (text), data, and
stack regions.
• Separate stack for user and kernel mode.
• PID (Process ID)
• Processes are either user processes, daemon
processes, or kernel processes.
• Daemons are not associated with user, but do
system wide functions. Init may create daemons that
exist throughout the life of the system or as needed.

13
O.S. by Er. K.S.Dhindsa © 2007
Process Management

• Initial boot process (0) forks a child (process 1) and


process 0 becomes the swapper. Process 1 is init
process and is ancestor of all other processes.
• Parent/Child/Sibling relationship indicated by pointers
in process table.
• Execve usually called to replace memory portion of
new process.
• Exit – process termination
• Wait – Parent waits for child to exit. Reclaims
process resources.
• Process group ID (GID) in process table

14
O.S. by Er. K.S.Dhindsa © 2007
Process Management

 Round robin multilevel feedback queue

 At end of context switch, kernel executes algorithm to


schedule a process

 Highest priority process which is ready is scheduled.


On tie, picks the one which has waited the longest.

15
O.S. by Er. K.S.Dhindsa © 2007
CPU SCHEDULING
• Every process has a scheduling priority associated with it;
larger numbers indicate lower priority.
• Negative feedback in CPU scheduling makes it difficult for a
single process to take all the CPU time.
• Process aging is employed to prevent starvation.
• When a process chooses to relinquish the CPU, it goes to
sleep on an event.
• When that event occurs, the system process that knows
about it calls wakeup with the address corresponding to the
event, and all processes that had done a sleep on the
same address are put in the ready queue to be run.

16
O.S. by Er. K.S.Dhindsa © 2007
Memory Management

 The scheduler process (or swapper) decides which


processes to swap in or out, considering such factors as
time idle, time in or out of main memory, size, etc.

 If there is too much contention, processes are


swapped out until enough memory is available.
Allocation of both main memory and swap space is
done first-fit.

17
O.S. by Er. K.S.Dhindsa © 2007
FILE SYSTEM COMMANDS

• pwd - report your current directory


• cd <to where> - change your current directory
• ls <directory> -list contents of directory
• cp <old file> <new file> - copy
• mv <old file> <new file> - move (or rename)
• rm <file> -delete a file
• mkdir <new directory name> -make a directory
• rmdir <directory> -remove an empty directory
18
O.S. by Er. K.S.Dhindsa © 2007
UNIX through GENERATIONS

19
O.S. by Er. K.S.Dhindsa © 2007
UNIX

20
O.S. by Er. K.S.Dhindsa © 2007
UNIX Utility Programs

21
O.S. by Er. K.S.Dhindsa © 2007
UNIX Kernel

22
O.S. by Er. K.S.Dhindsa © 2007
PROCESS CONTROL -- UNIX

• Processes communicate via pipes; queues of bytes


between two processes that are accessed by a file
descriptor.
• All user processes are descendants of one original
process, init.
• init forks a getty process: initializes terminal line
parameters and passes the user’s login name to login.
– login sets the numeric user identifier of the process to
that of the user
– executes a shell which forks subprocesses for user
commands.

23
O.S. by Er. K.S.Dhindsa © 2007
USER INTERFACE IN UNIX

• Programmers and users mainly deal with already existing


systems programs: the needed system calls are
embedded within the program and do not need to be
obvious to the user.
• The most common systems programs are file or directory
oriented.
– Directory: mkdir, rmdir, cd, pwd
– File: ls, cp, mv, rm
• Other programs relate to editors (e.g., emacs, vi) text
formatters (e.g., troff, TEX), and other activities.

24
O.S. by Er. K.S.Dhindsa © 2007
PROCESS CONTROL BLOCKS
• The most basic data structure associated with processes is
the process structure.
– unique process identifier
– scheduling information (e.g., priority)
– pointers to other control blocks
• The virtual address space of a user process is divided into
text (program code), data, and stack segments.
• Every process with sharable text has a pointer form its
process structure to a text structure.
– always resident in main memory.
– records how many processes are using the text segment
– records were the page table for the text segment can be
found on disk when it is swapped. 25
O.S. by Er. K.S.Dhindsa © 2007
PAGING

• Berkeley UNIX systems depend primarily on paging for


memory-contention management, and depend only
secondarily on swapping.
• Demand paging – When a process needs a page and the
page is not there, a page fault to the kernel occurs, a frame
of main memory is allocated, and the proper disk page is
read into the frame.
• If the scheduler decides that the paging system is
overloaded, processes will be swapped out whole until the
overload is relieved.

26
O.S. by Er. K.S.Dhindsa © 2007
C-LISTS

• Terminal drivers use a character buffering system which


involves keeping small blocks of characters in linked lists.
• A write system call to a terminal enqueues characters on
a list for the device. An initial transfer is started, and
interrupts cause dequeueing of characters and further
transfers.
• Input is similarly interrupt driven.
• It is also possible to have the device driver bypass the
canonical queue and return characters directly form the
raw queue — raw mode (used by full-screen editors and
other programs that need to react to every keystroke).

27
O.S. by Er. K.S.Dhindsa © 2007
System Calls for Process Management
A file is represented by an inode — a record that
stores information about a specific file on the disk.

s is an error code
pid is a process ID
residual is the remaining time from the previous alarm
28
O.S. by Er. K.S.Dhindsa © 2007
Booting UNIX

The sequences of processes used to boot some systems


29
O.S. by Er. K.S.Dhindsa © 2007
NETWORKING

Use of sockets for networking


30
O.S. by Er. K.S.Dhindsa © 2007
UNIX I/O SYSTEM

31
O.S. by Er. K.S.Dhindsa © 2007
INTERPROCESS COMMUNICATION

• The pipe is the IPC mechanism most


characteristic of UNIX

– Permits a reliable unidirectional byte stream


between two processes.
– A benefit of pipes small size is that pipe data
are seldom written to disk; they usually are
kept in memory by the normal block buffer
cache.

32
O.S. by Er. K.S.Dhindsa © 2007
UNIX File System

Some important directories found in most UNIX systems

33
O.S. by Er. K.S.Dhindsa © 2007
UNIX File System

(a) Before mounting. (b) After mounting


34
O.S. by Er. K.S.Dhindsa © 2007
LOCKING FILES

(a) File with one lock


(b) Addition of a second lock
35
(c) A third lock O.S. by Er. K.S.Dhindsa © 2007
UNIX FILE SYSTEM
Disk layout in classical UNIX systems

Structure of the i-node 36


O.S. by Er. K.S.Dhindsa © 2007
UNIX FILE SYSTEM

The relation between the file descriptor table, the open file
description 37
O.S. by Er. K.S.Dhindsa © 2007
SECURITY IN UNIX

Some examples of file protection modes

38
O.S. by Er. K.S.Dhindsa © 2007
O.S. by Er. K.S.Dhindsa © 2007

CASE STUDY – UNIX

Lecture Series By :

Er. Kanwalvir Singh Dhindsa

Deptt. of CSE & IT

www.dhindsa.info

39

You might also like