You are on page 1of 107

OPERATING SYSTEMS

Chapter 1
Introduction

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
What Is An Operating System?

Lots of hardware !!

• One or more processors


• Main memory
• Disks
• Printers
• Various input/output devices

Managing all these components requires a layer of


software – the operating system

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
What is an Operating System (2)?

• An Operating System is a program that acts as an


intermediary/interface between a user of a computer
and the computer hardware.
• OS goals:
– Control/execute user/application programs.
– Make the computer system convenient to use.
– Ease the solving of user problems.
– Use the computer hardware in an efficient manner.

A. Frank - P. Weisberg
Services provided by an OS
• Facilities for program creation
– editors, compilers, linkers, debuggers, etc.
• Program execution
– loading in memory, I/O and file initialization.
• Access to I/O and files
– deals with the specifics of I/O and file formats.
• System access
– resolves conflicts for resource contention.
– protection in access to resources and data.

A. Frank - P. Weisberg
Where is the software?

Where the operating system fits in.

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Operating System as an Extended
Machine

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Operating System as a Resource
Manager

• Allow multiple programs to run at the same time


• Manage and protect memory, I/O devices, and
other resources
• Multiplexes (shares) resources in two different
ways:
• In time
• In space

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
History of Operating Systems
Generations:

• (1945–55) Vacuum Tubes


• (1955–65) Transistors and Batch Systems
• (1965–1980) ICs and Multiprogramming
• (1980–Present) Personal Computers, Tablets,
Phones

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Transistors and Batch Systems (1)

Figure 1-3. An early batch system.


(a) Programmers bring cards to 1401.
(b)1401 reads batch of jobs onto tape.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Transistors and Batch Systems (2)

Figure 1-3. (c) Operator carries input tape to 7094.


(d) 7094 does computing. (e) Operator carries output tape to
1401. (f) 1401 prints output.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Transistors and Batch Systems (4)

Figure 1-4. Structure of a typical FMS job.


Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
ICs and Multiprogramming

A multiprogramming system
with three jobs in memory.
More third generation
• Time Sharing (CTSS)
• Multics
• Unix
• Linux

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Fourth generation

• PCs
• Network Operating Systems
• Distributed Operating Systems

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Operating system timeline
• First generation: 1945 – 1955
– Vacuum tubes
– Plug boards
• Second generation: 1955 – 1965
– Transistors
– Batch systems
• Third generation: 1965 – 1980
– Integrated circuits
– Multiprogramming
• Fourth generation: 1980 – present
– Large scale integration
– Personal computers
• Next generation: ???
– Systems connected by high-speed networks?
– Wide area resource management?
First generation: direct input
• Run one job at a time
– Enter it into the computer (might require rewiring!)
– Run it
– Record the results
• Problem: lots of wasted computer time!
– Computer was idle during first and last steps
– Computers were very expensive!
• Goal: make better use of an expensive commodity: computer
time

CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)


Second generation: batch
systems

• Bring cards to 1401


• Read cards onto input tape
• Put input tape on 7094
• Perform the computation, writing results to output tape
• Put output tape on 1401, which prints output

Chapter 1
Structure of a typical 2nd generation job

Data for
$END
program

$RUN
FORTRAN $LOAD
program

$FORTRAN
$JOB, 10,6610802, ETHAN MILLER

CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)


Spooling
• Original batch systems used tape drives
• Later batch systems used disks for buffering
– Operator read cards onto disk attached to the computer
– Computer read jobs from disk
– Computer wrote job results to disk
– Operator directed that job results be printed from disk
• Disks enabled simultaneous peripheral operation on-line
(spooling)
– Computer overlapped I/O of one job with execution of another
– Better utilization of the expensive CPU
– Still only one job active at any given time

CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)


Third generation: multiprogramming
• Multiple jobs in memory
– Protected from one another
Job 3 • Operating system
protected from each job
as well
Job 2
• Resources (time,
Memory
Job 1 hardware) split between
partitions
jobs
• Still not interactive
Operating – User submits job
system – Computer runs it
– User gets results minutes
(hours, days) later
Timesharing
• Multiprogramming allowed several jobs to be active at
one time
– Initially used for batch systems
– Cheaper hardware terminals -> interactive use
• Computer use got much cheaper and easier
– No more “priesthood”
– Quick turnaround meant quick fixes for problems
What Operating Systems Do
• Depends on the point of view
• Users want convenience, ease of use and good
performance
– Don’t care about resource utilization
• But shared computer such as mainframe or
minicomputer must keep all users happy
• Users of dedicate systems such as workstations have
dedicated resources but frequently use shared resources
from servers
• Handheld computers are resource poor, optimized for
usability and battery life
• Some computers have little or no user interface, such as
embedded computers in devices and automobiles
Operating System Definition
• OS is a resource allocator
– Manages all resources
– Decides between conflicting requests for efficient and fair resource
use
• OS is a control program
– Controls execution of programs to prevent errors and improper use
of the computer
Operating System Definition
(Cont.)
• No universally accepted definition
• “Everything a vendor ships when you order an operating
system” is a good approximation
– But varies wildly
• “The one program running at all times on the computer”
is the kernel.
• Everything else is either
– a system program (ships with the operating system) , or
– an application program.
Computer Startup
• bootstrap program is loaded at power-up or reboot
– Typically stored in ROM or EPROM, generally known as firmware
– Initializes all aspects of system
– Loads operating system kernel and starts execution
Types of modern operating systems
• Mainframe operating systems: MVS
• Server operating systems: FreeBSD, Solaris
• Multiprocessor operating systems: Cellular IRIX
• Personal computer operating systems: Windows, Unix
• Real-time operating systems: VxWorks
• Embedded operating systems
• Smart card operating systems
 Some operating systems can fit into more than one category
Computer System Organization
• Computer-system operation
– One or more CPUs, device controllers connect through common bus
providing access to shared memory
– Concurrent execution of CPUs and devices competing for memory
cycles
Computer-System Operation
• I/O devices and the CPU can execute concurrently
• Each device controller is in charge of a particular device
type
• Each device controller has a local buffer
• CPU moves data from/to main memory to/from local
buffers
• I/O is from the device to local buffer of controller
• Device controller informs CPU that it has finished its
operation by causing an interrupt
Common Functions of Interrupts
• Interrupt transfers control to the interrupt service
routine generally, through the interrupt vector,
which contains the addresses of all the service
routines
• Interrupt architecture must save the address of
the interrupted instruction
• A trap or exception is a software-generated
interrupt caused either by an error or a user
request
• An operating system is interrupt driven
I/O by Interrupts

Generate an interrupt when I/O is finished.


e.g. When character is finished being printed, interrupt CPU.
Allows CPU to do something else while character is
being printed
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Interrupt Timeline
I/O Structure
• After I/O starts, control returns to user program only upon
I/O completion
– Wait instruction idles the CPU until the next interrupt
– Wait loop (contention for memory access)
– At most one I/O request is outstanding at a time, no
simultaneous I/O processing
• After I/O starts, control returns to user program without
waiting for I/O completion
– System call – request to the OS to allow user to wait for I/O
completion
– Device-status table contains entry for each I/O device
indicating its type, address, and state
– OS indexes into I/O device table to determine device status
and to modify table entry to include interrupt
I/O Devices
• Controller runs a device-accepts commands from
the OS and executes them
• Complicated business
• E.g. gets command to read sector x on disk y. Must convert to (cylinder,
sector, head) address, move arm to correct cylinder, wait for sector to
rotate under the head, read and store bits coming off the drive, compute
checksum, store bits as words in memory

• Controller contains a computer to run its device

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Device Driver
• OS software that talks to controller-gives
commands, accepts responses
• Each controller manufacturer supplies a driver
for each OS
• Driver runs in kernel mode
• Controller has registers which are used to
communicate with the driver
• Three modes of communication
• Polling
• Interrupts
• DMA

Tanenb aum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
I/O by polling device
• Driver issues command to controller
• Driver polls device until it is ready
• E.g. Send character to printer controller and
poll until it is ready to accept the next
character
• Big use of CPU
• Called programmed I/O-not really used any
more

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
I/O by DMA
• Special (controller) chip
• Avoids using the CPU as part of the transfer
to/from memory
• CPU tells chip to set up transfer and take care
of it
• Chip does as it is told and interrupts CPU when
it is finished

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The bus hierarchy
• In the beginning there was one bus-couldn’t
handle the traffic when cpu and memories got
faster and bigger
• Create a hierarchy of faster buses (PCI) and
specialized buses (SCSI, USB)

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Pentium System Buses

The structure of a large Pentium system


Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Interrupt Handling
• The operating system preserves the state of the
CPU by storing registers and the program
counter
• Determines which type of interrupt has occurred:
– polling
– vectored interrupt system
• Separate segments of code determine what
action should be taken for each type of interrupt
CPU internals

Execute
Fetch Decode unit
unit unit

Fetch Decode Execute Execute


Buffer unit
unit unit unit

Fetch Decode
unit unit Execute
unit

Pipelined CPU Superscalar CPU

CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)


Operating System Structure
• Multiprogramming (Batch system) needed for
efficiency
– Single user cannot keep CPU and I/O devices busy at all times
– Multiprogramming organizes jobs (code and data) so CPU always has one to
execute
– A subset of total jobs in system is kept in memory
– One job selected and run via job scheduling
– When it has to wait (for I/O for example), OS switches to another job

• Timesharing (multitasking) is logical extension in which


CPU switches jobs so frequently that users can interact with each job while it
is running, creating interactive computing
– Response time should be < 1 second
– Each user has at least one program executing in memory process
– If several jobs ready to run at the same time  CPU scheduling
– If processes don’t fit in memory, swapping moves them in and out to run
– Virtual memory allows execution of processes not completely in memory
Memory Layout for Multiprogrammed System
Operating-System Operations
• Interrupt driven (hardware and software)
– Hardware interrupt by one of the devices
– Software interrupt (exception or trap):
• Software error (e.g., division by zero)
• Request for operating system service
• Other process problems include infinite loop,
processes modifying each other or the
operating system
Transition from User to Kernel
Mode
• Timer to prevent infinite loop / process hogging resources
– Timer is set to interrupt the computer after some time period
– Keep a counter that is decremented by the physical clock.
– Operating system set the counter (privileged instruction)
– When counter zero generate an interrupt
– Set up before scheduling process to regain control or terminate program
that exceeds allotted time
Processes
• Program in execution
• Lives in address space
• Process table needed
• Keeps information about process
• Used to re-start process

• Shell (command interpreter) reads commands


from terminal

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
A Process Tree

Process creates child processes


Tree structure

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Process
• Can communicate with one another
• Have UID’s and group ID’s (GID)
• Can communicate with one another (IPC)

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Process Management
• A process is a program in execution. It is a unit of work
within the system. Program is a passive entity, process is
an active entity.
• Process needs resources to accomplish its task
– CPU, memory, I/O, files
– Initialization data
• Process termination requires reclaim of any reusable
resources
• Single-threaded process has one program counter
specifying location of next instruction to execute
– Process executes instructions sequentially, one at a time, until completion
• Multi-threaded process has one program counter per
thread
• Typically system has many processes, some user, some
operating system running concurrently on one or more
CPUs
– Concurrency by multiplexing the CPUs among the processes / threads
Process Management Activities
The operating system is responsible for the following
activities in connection with process management:
• Creating and deleting both user and system
processes
• Suspending and resuming processes
• Providing mechanisms for process synchronization
• Providing mechanisms for process communication
• Providing mechanisms for deadlock handling
Main Memory
• RAM
• ROM-can’t be changed. Fast, cheap
• e.g. keeps bootstrap OS loader
• EEPROM (Electrically Erasable PROM) Can be
re-written, but slowly
• e.g. serves as films in digital cameras, as
disk in portable music players

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Memory Management
• To execute a program all (or part) of the instructions must
be in memory
• All (or part) of the data that is needed by the program
must be in memory.
• Memory management determines what is in memory and
when
– Optimizing CPU utilization and computer response to users
• Memory management activities
– Keeping track of which parts of memory are currently being used and by
whom
– Deciding which processes (or parts thereof) and data to move into and
out of memory
– Allocating and deallocating memory space as needed
Storage Management
• OS provides uniform, logical view of information storage
– Abstracts physical properties to logical storage unit - file
– Each medium is controlled by device (i.e., disk drive, tape drive)
• Varying properties include access speed, capacity, data-
transfer rate, access method (sequential or random)
• File-System management
– Files usually organized into directories
– Access control on most systems to determine who can access what
– OS activities include
• Creating and deleting files and directories
• Primitives to manipulate files and directories
• Mapping files onto secondary storage
• Backup files onto stable (non-volatile) storage media
Mass-Storage Management
• Usually disks used to store data that does not fit in main
memory or data that must be kept for a “long” period of
time
• Proper management is of central importance
• Entire speed of computer operation hinges on disk
subsystem and its algorithms
• OS activities
– Free-space management
– Storage allocation
– Disk scheduling
• Some storage need not be fast
– Tertiary storage includes optical storage, magnetic tape
– Still must be managed – by OS or applications
– Varies between WORM (write-once, read-many-times) and RW (read-
write)
Storage pyramid
Capacity Access latency
< 1 KB Registers 1 ns Better

1 MB Cache (SRAM) 2–5 ns


256 MB Main memory (DRAM) 50 ns
40 GB Magnetic disk 5 ms
Better > 1 TB Magnetic tape 50 sec

• Goal: really large memory with very low latency


– Latencies are smaller at the top of the hierarchy
– Capacities are larger at the bottom of the hierarchy
• Solution: move data between levels to create illusion
of large memory with low latency
Disk drive structure
• Data stored on surfaces head
– Up to two surfaces per platter
sector
– One or more platters per disk
• Data in concentric tracks
– Tracks broken into sectors platter
• 256B-1KB per sector
track
– Cylinder: corresponding tracks
on all surfaces cylinder
• Data read and written by
heads
surfaces
– Actuator moves heads
– Heads move in unison
spindle
actuator
Memory
Address Address
0x2ffff 0x2ffff
User program User data
0x2d000
and data
0x2b000 0x2bfff Limit2
User data
0x27fff Limit 0x29000 Base2
User program
0x24fff Limit1
0x23000 and data User program
Base 0x23000 Base1
0x1dfff 0x1dfff
Operating Operating
0
system 0
system

• Single base/limit pair: set for each process


• Two base/limit registers: one for program, one for
data
Anatomy of a device request

Instructionn
3 2
1: Interrupt Instructionn+1
5 Interrupt Disk
CPU controller controller
1 6 4 Operating
system 3: Return
Interrupt handler
2: Process interrupt
• Left: sequence as seen by hardware
– Request sent to controller, then to disk
– Disk responds, signals disk controller which tells interrupt
controller
– Interrupt controller notifies CPU
• Right: interrupt handling (software point of view)
Computer Hardware Review

Some of the components of a simple personal computer.


CPU Pipelining

Figure 1-7. (a) A three-stage pipeline. (b) A superscalar CPU.

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Caches
 Main memory is divided into cache lines (64 bytes)
 0-63 in line 1, 64-127 in line 2
 When program reads a word-cache hardware checks to
see if in cache.
 If so, then have a cache hit (2 cycles).
 Otherwise, make request of main memory over the
bus (expensive)
 Cache is expensive and is therefore limited in size
 Can have cache hierarchies
 Cache other things, like URL addresses

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The 4 Cache Questions
• When to put a new item into the cache? (on a
cache miss)
• Which cache line to put the new item in?
(memory word determines which line)
• Which item to remove from the cache when a
slot is needed? (same line new data goes into)
• Where to put a newly evicted item in main
memory? (memory address determines this)

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Multithreaded and Multicore Chips

(a) A quad-core chip with a shared L2 cache.


(b) A quad-core chip with separate L2 caches.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Operating System Zoo

• Mainframe operating systems


• Big-thousands of disks….
• Lots of jobs with lots of I/O
• Services-batch (payroll) transactions (airline
reservations, timesharing (query database)
• Elderly-Unix, Linux replacing them

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Operating System Zoo

• Server operating systems


• Workstations
• File, print, web servers
• BSD, Linux, Windows
• Multiprocessor operating systems
• Use multiple cores

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Operating System Zoo

• PC operating systems-Linux, Mac, Windows


• Smart phone operating systems- Android, iPhone,
Blackberry
• No hard disk
• Palm, Symbian popular OS’s

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Operating System Zoo

• Embedded operating systems-TV sets, cars,


DVDs, MP3s
• Everything is in ROM (no apps can run on it)
• QNx, Vxworks
• Real time operating systems
• Hard (eg. factory) deadline
• Soft (eg. multi-media) deadline
Smart card OS (eg border crossing cards)
• Java in ROM

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Operating System Concepts
• Processes
• Address spaces
• Files
• Input/Output
• Protection
• The shell

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Views of an Operating System
• There are three classical views (in literature):
1. Resource Manager – manages and allocates resources.
2. Control program – controls the execution of user programs and
operations of I/O devices.
3. Command Executer – Provides an environment for running user
commands.
• But one more modern view: the Operating System as a
Virtual Machine.

A. Frank - P. Weisberg
1. Resource Manager

• Resource Manager:
– Manages and protects multiple computer resources: CPU,
Processes, Internal/External memory, Tasks,
Applications, Users, Communication channels, etc…
– Handles and allocates resources to multiple users or
multiple programs running at the same time and space
(e.g., processor time, memory, I/O devices).
– Decides between conflicting requests for efficient and
fair resource use (e.g., maximize throughput, minimize
response time).
• Sort of a bottom-up view.
A. Frank - P. Weisberg
OS as a Resource Manager

A. Frank - P. Weisberg
Resource Manager oriented OS names
• DEC RSX – Resource Sharing eXecutive
• MIT Multics – MULTiplexed Information and
Computing Services
• IBM MFT/MVT – Multiple Fixed/Variable
Tasks
• IBM MVS – Multiple Virtual Storage
• DEC VMS – Virtual Memory System
• MVS TSO – Time Sharing Option
• CTSS – Compatible Time Sharing System
• IBM VM – Virtual machine
A. Frank - P. Weisberg
2. Control Program
• Control Program:
– Manages all the components of a complex
computer system in an integrated manner.
– Controls the execution of user programs
and I/O devices to prevent errors and
improper use of computer resources.
– Looks over and protects the computer:
Monitor, Supervisor, Executive,
Controller, Master, Coordinator ….
• Sort of a black box view.

A. Frank - P. Weisberg
Control program oriented OS names
• Unisys MCP – Master Control Program
• DR CP/M – Control Program/Microcomputer
• IBM VM/CP – VM Control Program
• IBM AIX – Advanced Interactive eXecutive
• DEC RSX – Resource Sharing eXecutive

A. Frank - P. Weisberg
3. Command Executer

• Command Executer:
– Interfaces between the users and machine.
– Supplies services/utilities to users.
– Provides the users with a convenient CLI
(Command Language Interface), also
called a Shell (in UNIX), for entering the
user commands.
• Sort of a top-down view.

A. Frank - P. Weisberg
Command Executer oriented OS names
• IBM AIX – Advanced Interactive Executive
• IBM VM/CMS – Conversational monitor System

A. Frank - P. Weisberg
File directory

The directory is organized as a tree


Root directory at the top. Path proceeds from the root (e.g. faculty/prof
brown/courses)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Mounting Files in UNIX

A CD-ROM is mounted on directory b.

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Special files
• Special files-can use same calls for I/O as for
files. OS treats them as files.
• Block special files (disks)
• Character special files (line printers,
modems)
• Kept in /dev directory, e.g. /dev/lp is line
printer

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Unix Pipe
Processes communicate by writing into/reading from a file
in Unix

A and B write into the pipe and read from the pipe.

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
I/O, Protection/Shell
• I/O-big part of OS
• Protection-UNIX uses rwx bits for each file
• 3 bits for owner, 3 for group, 3 for everyone else
• Shell (command interpreter)
• UNIX
• Has lots of flavors-sh,bash,csh,ssh…..
• Sort<file1>file2
• Cat file 1 file 2 file3 | sort > /dev/lp

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
System Calls
• Interface between user programs and OS
• Varies from OS to OS
• System call issued by user program
• Call uses a library call of the same name
• Library routine puts machine into kernel modes
(by issuing a special instruction)
• Finds actual routine for system call in a table
• Does the work involved in the call
• Returns to user program

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Unix Read System Call

• Count=read(fd, buffer, nbytes)


• fd is a file descriptor. When a file is opened, permissions are
checked. If access is allowed, a number (fd) is returned. Then
file can be read/written

• nbytes is number of bytes in file

• buffer is where read deposits the bytes

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
System Calls

read(fd, buffer, nbytes).


Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Look at System Calls
• Start with process management
• See how they are used in shell
• Then you write a shell
• Then do a brief summary of calls for
• File management
• Other useful calls

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
System Calls for Process Management

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Memory Layout
Processes have three segments:
text, data, and stack.

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Shell

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Fork
• Pid=fork( )
• Duplicates parent process completely
Everything duplicated -data,registers,fd’s
• Fork returns a value (pid)
• Zero in child
• Child’s PID in parent
• Used to differentiate child from parent

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Execve
• Replaces process’ core image by the file named
in its invocation
• Execve(name,arg,environp) has 3 parameters
• Name of file (e.g. cp command)
• Arg-pointer to argument array
• Environp-pointer to environment array

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Excve (example)
• cp f1 f2 is located by execve and parameters
are passed to it by execve

• Main(argc, argv, envp) is main prog in cp


• Argc is #items on command line (=3 in cp)
• Argv points to array (arg[0] points to cp, arg[1] points to f1,
• Envp points to environment, an array of name=value with
info like terminal type

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
System Calls for File Management

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File mode

• System keeps track of it


• Regular, special
• Date of creation
• Size
• Access status of file via stat command

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
System Calls for Directory and File
Management

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Linking

o In Unix, each file is identified by an i-number


o i-number indexes into i-node table
o Link creates a new directory entry with same i-number
o Has a new name (note instead of memo)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Mount System Call

• mount(“/dev/fd0”, “/mnt”, 0) is system call


• File comes from drive 0 and is mounted on binary
file /mnt.
• Third parameter tells if it is read or read-write
• Result is that file on drive zero can be accessed
from a directory
• Saw this example before with CD-same
mechanism for memory sticks and portions of hard
drives

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Other System Calls

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Windows Win32 API

The Win32 API calls that roughly correspond


to the UNIX calls
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Operating Systems Structure
Monolithic systems
• A main program that invokes the requested
service procedure.
• A set of service procedures that carry out the
system calls.
• A set of utility procedures that help the service
procedures.

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Monolithic Systems

A simple structuring model for a monolithic system.

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Layered Systems-THE operating system

Dijkstra’s the author

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Microkernels
• Small number of processes are allowed in the
kernel
• Minimizes effects of bugs
• Don’t want bug in driver to crash system
• Put mechanism in kernel and policy outside the
kernel
• Mechanism- schedule processes by priority
scheduling algorithm
• Policy-assign process priorities in user space

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Microkernels

Structure of the MINIX 3 system.

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Client-Server Model

The client-server model over a network.

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Virtual Machines (1)

The structure of VM/370 with CMS.

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Virtual Machines (2)

(a) A type 1 hypervisor. (b) A type 2 hypervisor.

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The World According to C

• The C language
• Header files
• Large programming projects
• The model of run time

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Model of Run Time

The process of compiling C and header files to make an


executable.

You might also like