0% found this document useful (0 votes)
61 views

Chapter 1 Handout Operating System

This document provides an introduction to operating systems, including: 1. It outlines the history of operating systems from the earliest computers in the 1940s-50s using vacuum tubes, to the development of batch processing systems in the 1950s-60s and time-sharing systems in the 1960s-80s. 2. It defines an operating system as software that manages hardware resources and provides common services for running application programs. 3. It describes the core functions of an operating system, including managing processors, memory, devices, and allocating resources for users and programs in a multi-user environment.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Chapter 1 Handout Operating System

This document provides an introduction to operating systems, including: 1. It outlines the history of operating systems from the earliest computers in the 1940s-50s using vacuum tubes, to the development of batch processing systems in the 1950s-60s and time-sharing systems in the 1960s-80s. 2. It defines an operating system as software that manages hardware resources and provides common services for running application programs. 3. It describes the core functions of an operating system, including managing processors, memory, devices, and allocating resources for users and programs in a multi-user environment.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Chapter 1: Introduction to operating system

1. History of OS
2. Definition of OS
3. OS services
4. Types of OS
5. OS Structure

History of Operating System


• The first true computer was designed by English Mathematician Charles Babbage (1792 -
1871).
• Babbage realized he would need S/W for analytic engine, he hired a woman Ada
Lovelace as I programmer. The programming language was Ada named after her.
• First generation of OS (1945 -1955) – Vacuum tubes
– Prof John Atanasoff & his student Clifford BEng built considered as first
functioning digital computer at lowa state university
– 300 vacuum tubes
– Same time – Konrad zuse in berlin built the Z3 computer with relays

Figure 1: Vacuum tubes

• Others initiation to invent system


– 1944 Colossus was built by a group at Bletchley park, England
– Mark I was built by Howard Aiken at Harvard
– ENIAC was built by William Mauchley & his student J. Presper
Eckert at pennsylvania
– Out of all some built by binary, vacuum tubes, programmable all were very
primitive & took seconds to perform even a simplest calculation
• Single group of people designed, built, programmed, operated & maintain each machine
• Program was done in machine language, by wiring up electrical circuits, by connecting
cable to plug boards to control machine basic functions (no programming no assembly
language)
• Sign-up for the block to time, using sign-up sheet on the wall then came down to
machine room, insert plug board in to the computer. Hoping that 20,000 vacuum tube
are not burnt & have to wait for some hours
• In 1950’s punch cards are introduced, then onwards programs were written on punch
cards
2nd Generation of OS (1955-1965) Transistors & Batch System’s
• First time there was a clear separation between
– Designers, Builders
– Operators, programmers
– Maintenance personal

Figure 2: Transistors

• These machines now called mainframes, they are locked in A/C rooms
• Separate staffs are allocated to manage them
• Only rich people would offered to buy, Government agencies, Universities, higher
educational institution’s etc..
• To run jobs programmer would write program in the paper then punch it on the cards
• Then card to the input room then hand over to the operator (it will take much time to
finish the job)
• Batch system
• Collect tray full of Jobs from the Input room then read them in the magnetic
tapes using small inexpensive computer IBM 1401
• IBM 7094 used for real computing
• The operator load the program which read the tape & ran it the Output was
written on the second tape
• Then next job, after all the Job (whole batch ) was done the operator remove the
I/p & O/p tapes replace with next job
• The operator take the O/p tape to 1401 for printing

Figure 3: The job of Programmer, operator, IBM 1401, IBM 7094


Figure 4: Ordering of jobs through punch cards

3rd Generation of OS (1965-1980) Multiprogramming & IC’s


• Technique used
– Multi programming
– SPOOLING
– Compatible TSS
– MULTICS multiplexed Information Computing Service
• IBM 360 (bring 1401 & 7904 together), 370, 4300, 3080, 3090
• IBM designed 1st floppy disk with 8 inches with 8 Kilobits (1967)
• Then in 1986 FDD with 3*1/2 inch with 1.44 MB
• DEC PDP -1 called as minicomputer with 4K of 18-bit work
• DEC PDP -7 is designed when working with MULTICS
• LINUX then MINIX (1987) Then LINUX
Figure 5: Multiprogramming

4th Generation of OS (1980 onwards) LSI, Circuit, Chips, etc…


• Micro computers / personal computers
• PDP – 11
• 1974 IBM’s Intel 80801st general purpose 8 bit CPU
It needs OS, kildall worte disk based O.S called CP/M (control program for
microcomputer)
• 1980 IBM designed IBMPC & look for S/W to run it
• IBM contacted Bill Gates to licenses his basic interpreter
• Gates suggest to contact Digital research
• kildall refused to meet IBM
• IBM went to Gates
• Gates approached “seattle computer product for a suitable OS (DOS) ”
• Gates approached to buy which they accepted
• Gates offered IBM a DOS/BASIC package which IBM accepted
• IBM was in need of modification
• Gates hired a person who wrote DOS
• The person who wrote DOS currently was an employee of fledging company, since
microsoft has hired employee the revised product was named MS-DOS and quickly came
to dominate IBM PC market
• 1983 IBM PC came out with intel 80286 CPU, 80386 CPU, 80486 CPU.
• Micro soft has some work outs of unix in his OS called XENIX
• MS upgrade, because of MACINTOSH success (24/1/11984)
• 1985 – 1995 just a simple graphical environment sitting on top of MS-DOS
• 1995 WINDOWS-95 only for booting old DOS programs
• WINDOWS- 98 slightly modified
• 95 & 98 are 16 bit Intel assembly
• WINDOWS NT 32 bit Dunid Cutler
• Cutler was also designer for VAX VMS OS
• Window NT uses most of features VAX VMS (case is resolved later)
• Window NT 4.0, 5.0, Window 2000
• Other version of 1998 called WINDOWS Millennium
• upgraded version of 2000 called WINDOWS XP (6 Years)
• Vista in 2007
• Windows 7
• Windows 8
• Windows 8.1
What is an Operating System?
• O.S: is a fundamental piece of software that runs in kernel mode (supervisor mode)
Definitions
1. A kernel is the core component of the OS, using inter-process communication & system
calls it act as a bridge b/w App’s and data processing which is performed at H/w level
2. It has complete access to all H/W & can execute any instruction the machine is capable
of executing
Kernel is responsible for low level task management such as Disk management, Task
Management & Memory Management
User mode
• Any user program runs in user mode can access RAM & H/W. program runs in user
mode is not allowed to do modifications to OS, allowing will create damage to OS.
• If a user really needs any of the features it makes a call to underlying API (Application
Program Interface) through which it can access
• Kernel mode to User mode (not done automatically by CPU)
• Interrupted by timers, keyboards, I/O when interrupt occurs CPU stops executing the
current running program

Software (kernel mode & user mode)


– Lowest level user mode software’s
1. User interface programs
2. Shell
3. GUI (graphical user interface)
• It allows user to start other programs such as web browser, email reader music reader
• Hardware (Chips boards & disks keyboards monitor)
• OS runs on H/W & provides base for all other S/W
Difference between OS & S/W
• If a user does not like particular software then he / she can free to get a different one /
write design own software. But can’t write a own interrupt handler (part of OS)
• OS differs from user programs
• OS are huge, complex, long lived
• The source code of Linux / windows or order of 5 million lines of codes (1000 volumes) –
additional things added 10 or 20 times to the total
• OS functions basically two unrelated functions
• Providing application programmers a clean abstract set of resources instead of messy
H/W ones
• Manage H/W resources
OS as extended machine
• stable: doesn’t crash
• portable: can run code on more than one type of machine
• reliable: always reacts in the same way
• safe: doesn’t do something dangerous
• well-behaved: acts in a proper manner
• Features:
• threads, processes, files, communication channels
OS as resource manager
– Support many devices simultaneously
1. e.g. keyboard, mouse, printer, speakers, microphone
2. Share resource among users and programs
– Fairly each programmer gets a chance to run
– Safely protects against corruption
– Efficiently using the available resource to provide the best service possible
Allocates resources to the user

1. Disks,
2. memory,
3. network interfaces,
4. timers, terminals/displays,
5. laser printers, etc (who using what / how it is shared)
• Maintain “multi-user” illusion to several users
– Most systems allow several user programs
– (even you think only one program is running, several internal programs is also
running)
• Managing
– Processor 1,2 or several
– Memories, RAM, cache
– Timers, internal & external
– Disks
– Network interface intranet, LAN, WAN
– Printers
• Processors
– It runs all software and moves data around
– CPU fetches instructions from memory and execute them
– As soon as information is fetched it decode to determine type & operands,
execute it, then subsequently do for all the instructions, then for the complete
program
– CPU contains registers (hold key variables & results)
– Special Registers
• Program counter (memory addr: of next instr: to be executed)
• Stack Pointer (points top of stack)
• Program Status Word (control bits)
– Execution

Figure 6: Pipeline

Superscalar CPU
Figure 7: Superscalar CPU

– System call (to obtain service from the OS, user program makes s/m call which
traps into kernel & appeal to the OS, trap instruction switches from user mode to
kernel mode)

• Multithreaded
– The ability of OS to simultaneously execute different parts of programs called
threads
– The programmer should carefully design the program in such a way that the
threads runs independently without interfering
– Thread is kind of light weight process (running in a program)
– Ex: if 1 process want to read a word from memory (it takes many clock cycles)
– Multithreaded CPU can switch to another thread
– Each thread appears to OS a separate CPU

Multicore chips
– Two or more independent processing units called cores, units that read &
execute program instructions
– Multiple core can run multiple instructions at the same time (increase overall
speed of the program)
– Cores is integrated into single circuit die know as chip multiprocessor or CMP /
multiple dies on to single chip package
Memory
– The second major component in computer is Memory
– Memory should be fast, large & cheap
– No approach satisfies all the three
– A new approach is taken by constructing hierarchy of layers in memory

Register
– Registers are internal to CPU, no delay in accessing registers
– Storage capacity available in them is 32*32 bit on a 32 bit CPU, 64 * 64 bit on 64
bit CPU.
– Programs manage registers themselves in software
Cache
– Controlled by Hardware
– Main memory is divided into cache lines 64 bytes
– 0 – 63 address in cache line 0
– 64 – 127 address in cache line 1 & so on …
– Most heavily used cache lines are kept in speed cache located inside or very
close to CPU.
– cache hit (2 clock cycles)
– Cache miss (goes to main memory)
– Cache memory is limited in size due high cost
– Some machines have 2 or 3 levels of cache
– Many OS will keep heavily used files in main memory instead of disk for repeated
lookups
– Example
– Home\users\projects\subprojects\kernel\check.c
– Into disk address where the file is located can be cached to avoid repeated
lookups
– Cache line 4096 (64 byte) 32 bit address 6b-17 bit used to specify the cache line
– Cache are good idea in modern CPU there are two cache L1 & L2
– Two L1 cache (1st L1 inside CPU, to feed the decoded instructions to execution
engine most CPU have 2nd L1 for very heavily used words)
– L1 cache 16 KB, access data without any delay
– L2 hold several megabytes of recently used words, access data with one or two
clock cycles
Main Memory
– Usually call it as RAM
– All CPU request that cannot be satisfied out of cache go to Main memory
– ROM is a non volatile memory it does not loose it content when power is
switched off
– ROM is programmed at factory and cannot be changed
– ROM is fast & inexpensive
– Some computer use bootstrap loader to start computer is contained in ROM
– FLASH
– CMOS (many computers use to hold current date and time, it can hold
configuration parameters such as which disk to boot)ALZHEIMER
Disks

– Magnetic disk (HARD DISK)


– Cheaper than RAM per bit
– A disk consist of 1 or more metal platters that rotate at 5400, 7200 or 10,800
rpm, a mechanical arm pivots over the platters from corner
– Information is written on the disk in a series of concentric circles
– At any given arm position each of the heads can read an angular region call track
– Together all the tracks for a given arm position form a cylinder
– Each track is divided into some number of sectors typically 512 bytes per sector
– On modern disk the outer cylinder contain more sector than the inner one
– Moving the arm from one cylinder to another takes 1 msec, then moving to
random cylinder takes 5 to 10 msec depending on drives
– Once the arm is in correct track the drive must wait for the needed sector to
rotate under the head additional delay of 5 to 10 msec depending on the drive’s
rpm
– Reading or Writing occurs at 50 Mb/sec on low end disks to 160 MB/sec on fast
ones.
Tapes
– The medium is often used as backup for disk storage and for holding very large
data sets
I/O Devices
– I/O devices heavily interact with OS
– I/O devices consist of two parts, controller part & device itself
– Controller is a chip or set of chips that physically controls the device
– It accepts commands from OS to read data from device & carries them out

Figure 8 Components of simple personal computer

A disk controller might accept command to read sector 11,206 from disk 2. The controller has
to convert this linear sector number to a cylinder, sector and head.
The controller has to determine which cylinder the disk arm is on and give it a sequence of
pulses to move in and out the requisite number of cylinders.
It has to wait until the proper sector has rotated under the head and then starts reading or
storing the bits as they come of the drive.
Finally it has to assemble the incoming bits into words and store them in memory.
Every controller has a small number of registers that are used to communicate with it.
For example a minimal disk controller might have registers for specifying the disk address,
memory address, sector count and direction
To activate the controller the driver gets a command from the OS. The collection of device
register forms the IO port space.
Input and output in 3 ways

1. In the simplest method a user program issues a system call, which the kernel translates
into procedure call to the driver. The driver starts the IO device, once the IO device has
completed the driver puts the data where they are needed and returns. The operating
system then returns control to the caller, this is called busy waiting
2. The driver start the device and ask it to give an interrupt when it is finished, at that
point driver returns. The OS blocks caller if need & looks for other work to do. When the
controller deduct the end of transfer, it generates and interrupt to signal completion.
3. DMA it is a chip that can control the flow of bits between memory and some controller
without CPU intervention. The CPU sets up the DMA chip telling how many bytes to
transfer, the device and memory address involved and the direction & lets it go.
Figure 9: Three step process for I/O

Step 1: The driver tells the controller by writing into the device register. The controller
then starts the device , once the controller has finished reading / writing
Step 2: It signals the interrupt controller chip using certain bus line

Step 3: If the interrupt controller is prepared to accept the interrupt it declare a pin on
the CPU chip informing IC

Step 4: IC puts the no of device on bus, so the CPU can read it and know which device
has just finished

Interrupt Vector: Is a memory location of Interrupt Handler which prioritizes interrupts and save if more
interrupt is waiting to be handled
Interrupt is a signal from a device attached to a computer / from a program within the computer, the
signal tells the OS to stop & device what to do next.
When an interrupt is generated the OS saves its execution state by means of CONTEXT SWITCH a
procedure that a computer processes follows to change from one task to another, by ensuring not to
conflict
Once the OS saves execution state is starts execution of Interrupt Handler at the Interrupt vector.
Buses

Figure 10 The structure of large pentium

Cache, Local, Memory, ISA, PCI, USB, SCSI & IDE

Cache bus is connected between CPU and L2Cache

Local bus is connected between PCI bridge and CPU


Memory bus is connected between Main memory and PCI bridge
ISA: Industry Standard Architecture
ISA runs at 8.33 MHz
Maximum speed 16.67 Mb/sec
It is backward compatible with old and slow I/O devices
PCI Peripheral Component Interconnect
runs at 66 MHz
Maximum speed 528 Mb/sec
PCI Express runs at 100 MHz it is connected in between CPU & PCI bridge & also
between PCI bridge and Main memory
USB 1.0 it transfers data at the rate of 1.5 Mb/sec
USB 2.0 it transfers data at the rate of 1.5 Mb/sec
SCSI small computer system interconnect
It transfers data at the rate of 160 Mb/sec, it is used to connect fast disk, scanners that
require high bandwidth
IEEE 1394 to connect multimedia devices
IDE Integrated Drive Electronics to connect disk and CD-ROMS

Booting the computer

On the mother board a program called as BIOS (basic input output system). The BIOS
contains low level I/O software, including procedures to read the keyboard, written to
the screen and do I/O disk among other thing
When a computer is started the BIOS is started, it first checks how much RAM is
installed and checks all other software are functioning properly
It starts out by scanning ISA and PCI bus to detect all the devices attached to them
BIOS then determines the boot device by trying a list of devices stored in CMOS memory
Typically an attempt is made to boot from the floppy device else an attempt will be
made to boot from the CD ROM, If neither of them is present then it will boot from the
hard disk
The first sector from the boot device is read into memory and executed, the sector
contains a program that normally examines partition table at the end of the boot sector
to determine which partition is active, then boot loader is read in from that partition.
the loader reads in the operating system from the active partition and starts it.

The Operating System ZOO

The Mainframe Operating System


A mainframe with 1000 disks and millions of gigabytes of data in not unusual. The
Operating Systems for mainframes are heavily oriented towards processing many jobs at
once. Most of which need abnormal amounts of I/O. They typically offer three kinds of
service, they are batch, transactions processing & Time sharing
A batch system is the one that proceed routing jobs, Example clams processing in an
insurance company or sales reporting for chain of stores is typically done in batch mode.
Transaction processing system handle large number of small request Example check
processing at a bank or air ticket reservation.
Each unit of work is small but the system must handle hundreds or thousands of
requests per second
Time sharing system must allow multiple remote users to run jobs on the computer at
once, Example querying a big database.
Server Operating System
They server multiple users at once over a network and allow the users to share a
hardware and software resources.
Servers can provide print service, file service or web service.
Typical servers Operating System are Solaris, FreeBSD, and Linux and windows server
200 x.
Multi processor Operating System
A common way to get major computing power is to connect multiple CPU into a single
system, depending on how precisely how they are connected and what is shared. These
systems are called parallel computers, multicomputer or multi processor.
With the recent advent of multicore chips for personal computers even conventional
desktop and notebook OS are starting to deal with at least small scale multiprocessor
and the number of core is likely to increase over time.
Personal Computer OS
Describe in own words
Handheld Computer OS
A handheld computer or PDA is a small computer that performs small number of
functions such as an electronic address book and memo pad
Almost all of them are based on 32 bit CPU with protected mode and run a sophisticated
operating system
One major difference is that handheld device does not have multigigabyte harddisk
which changes a lot.
Two of the most popular OS for handhelds are Symbian OS and palm OS.
Embedded OS
Examples of embedded OS are Microwave ovens, Tv sets, cars, DVD recorders & Mp3
players.
No untrusted software will not run on it, it is highly impossible to download new
application for microwave ovens all the software are in ROM.
Sensor OS
Networks of tiny sensor nodes are being deployed for numerous purpose these nodes
are tiny computer that communicate with each other and with a base station using
wireless communication. These sensor networks are used to guard national boarders,
detect forest fires, weather forecasting, etc.…
Each sensor node is real computer, with CPU, RAM, ROM and one or more
environmental sensors. It runs small but real OS, usually one that is event driven,
responding to external events or making measurements periodically based on internal
clocks, Tiny OS is well known os for sensor’s
Real time OS
Example for real time OS is Industrial process control system, real computer have to
collect data about the production process and use it to control mechanisms in the
factory. Often their hard deadlines to be met.
Two kinds of real time OS, Hard Real time OS and Soft real time OS
Hard real time OS is found in avionics, military and similar application areas, they all
focus on certain action will occur by a certain time
Soft real time OS in which missing occasional deadline while not desirable, is acceptable
and does not cause any permanent damage. Example digital audio or multimedia
systems fall in this category
Smart card OS
The smallest OS run on smart cards, which are credit card contain a CPU chip, they
server processing power and memory constraints. Some are powered by contacts in the
reader into which they are inserted, but contact less smart cards are inductively
powered which greatly limits what they can do. Some of them handle only single
function such as electronic payments. Others can handle multiple functions on the same
smart card.
Some smart cards are Java oriented, ROM on the card holds an interpreter for JVM, java
applets are downloaded to the card and are interpreted by JVM interpreter
Operating system concepts
Processes
A process is basically a program in execution. Associated with each process is its address
space. A list of memory location from o to maximum which the process can read and
write
Address space contains executable programs, program’s data its stack. Also associated
with each process is set of resources commonly including registers (Program counters,
stack pointers, PSW)
A process generally called as containers, when a process is temporarily suspended, it
must later be restarted in exactly the same state it had when it stopped. This
information about the process is explicitly saved some where during the suspension.
When a pointer is temporarily suspended all these pointers must be saved so that a read
call executed after the process is restarted will read the proper data.
All information about each process other than the contents of this address space is
stored in Operating System table called process table.
Address space is usually called as core image and its process table entry which contains
contents of its registers and many other items needed to restart the process later.
If a process can create one or more other processes and these processes in turn can
create child process, related processes that corporate to get come job done often need
to communicate with one another and synchronize their activities. This is called
Interprocess communication

Alarm signal: a process communicating another process on a different computer does


so by sending message to the remote process over a computer network. The sender
may request the OS notify it after a specified number of seconds, so that it can
retransmit the message If no acknowledgment is received for specified amount of time.
After setting the timer the user can focus on other task.
Files
System calls are needed to create files, remove files, read files. Before a file can be read,
it must be located on the disk and opened and after that it has been read it should be
closed, so calls are provided to do these things.
To provide a place to keep files, most operating systems have the concept of directory
as a way of grouping files together.
Every file within the directory hierarchy can be specified by giving its path name from
the top of the directory hierarchy, the root directory. Such absolute path names consist
of list of directories that must be traversed from the root directory to get the file with
slashes separating the components. The path for file CS101 is
/faculty/prof.brown/courses/CS101. The leading slash indicates the path is absolute,
that is starting the root directory.
In MS-DOS and Windows the backslash character is used as a separator instead of slash
(/) character so the file path would be written as \faculty\prof.brown\courses\CS101
Before a file can be read or written it must be opened at which time the permission are
checked. If the file is available or access is permitted the system returns a small integer
value called FILE DESCRIPTOR to use in subsequent operations. If the access is
prohibited an error code is returned.

Figure 11 A file system for a university department

UNIX uses mounted file system on a CD-ROM or DVD to be attached to main tree
Figure 12 (a) Before mounting the files on the CD-ROM are not accessible. (B) After mounting they are part of the file
hierarchy

The file system on the CD-ROM has been mounted on directory b thus allowing access
to files /b/x and /b/y
The UNIX has special files are provided in order to make I/O device look like files. That
way they can be written and read using same system calls are used for reading and
writing files. Two kinds of block special files block and character special files
Block special files consist of collection of randomly addressable blocks, such as disks. If I
want to read information say from block 4, a program can directly access 4 th block of the
device.
Character special files are used to model printer that accept or output a character
stream example: /dev/lp (connection to line printers)
Pipe is to connect to two processes, When process A wants to send data to process B it
writes on the pipe as though it were an output file. B can read data by reading from the
pipe as though it were an input file

Figure 13 Two process connected by a pipe

Protection
It consist of 9 bit binary protection code, it is divided into 3 three bit binary code, one
for the owner, one for owners of the members group, one for anybody who uses it.
Each field has a bit to read, to write, to execute. These three bits are known as RWX bits
Rwxr_x_ _x means the owners can do all the operations, members of the owners group
can only read and execute. But everyone else can execute the file.

The Shell
when a user logs in, the shell automatically starts, it has terminal as standard I/P and
standard O/P, it starts by typing in the prompt means that is tells waiting for the I/P to
accept command from user
if user types date
the shell starts by running the child process for date program the shell waits for
program to terminate
when the child process finishes, the shell types the prompt and wait to read the next I/P
line
date > file “the output is directed to a file”
sort <file1> file2 “which invoke the sort program from the I/P taken from a file and O/P
is given to file 2”
cat file1 file2 file3/sort> /dev/lp
concatenation file 1,2 & 3 then sort them and given then for line printer
cat file1 file2 file3/sort> /dev/lp &
concatenation will happen in the background, all the user to work another process / job
in the front end

System call in brief


To obtain service from OS, a user program must make system call, which TRAP’s in to kernel
and invoke the OS. The TRAP instruction switches from user mode to kernel mode and starts
the OS. When the work is completed the control is returned to the user program

System call in detail


Following is the detailed explanation of system call using a C code

Count = read (fd, buffer, nbytes);


1st parameter “fd” specifying the file
2nd parameter “buffer” pointing the buffer
3rd parameter “nbytes” number of bytes to read
All systems calls are invoked by C calling library procedures with the same name as the system
call: read
The system call returns the number of bytes actually read in count
This value is same as nbytes.
If the system call can’t be carried out due to invalid parameter or disk error , the count is set to
-1 & errno (error number) is put in global variable.
Programs should always check the results of system call to see if an error has occurred
Figure 13 the 11 steps in making the system call read (fd, buffer, nbytes)

The first and the third parameter are call by value, the second is pass by reference, means the
address of the buffer is passed not the content.
Then comes the actual call to the library procedure in (step 4), the instruction is the normal
procedural call instruction used to call all procedures.
The library procedure puts the system call number in the place where the OS expects it, such as
register (step 5)
Then it executes TRAP instruction to switch from user mode to kernel mode & start execution
at the fixed address within the kernel (step 6)
The kernel code that starts following the TRAP examines the system call number, & then
dispatches to the correct system call handler usually via table of pointers to system call
handlers (step 7)
System call handler runs (step 8)
Once the system call handler completed control may be transferred to user space library
procedure (step 9).
Then library procedure returns control to the user program (step 10)
Finally SP (stack pointer is incremented to read the next instruction from the user program –
step 11)
System call for process management
FORK is the only way to create a new process
It creates an exact duplicate of the original process which includes file descriptor, registers etc…
After fork the original and copy go their separate way
At the time of FORK all the variables will have identical values
After that parent’s data are copied to create child changes in one that does not affect other.
The FORK call returns a value zero in the child and equal to child process identifier PID in the
parent, the two process can see which one parent and child processes
In most of the cases child will need to execute different codes then the parent
Consider a case shell
It reads a command from the terminal
It creates child process to execute the command
When the child process is executed / terminated it reads the next command
To wait for the child to finish the parent execute waitpid system call which wait for the child to
terminate
Waitpid can wait for the child for any other old child to complete by setting the parameter -1
When it completes the address pointed to next parameter statloc will be set to the child’s exit
status
How FORK works
When a command is typed shell forks of a new process (child)
Child process executes the command using EXECVE system call which causes entire core image
is replaced by file named in its first parameter

# define TRUE 1
While (TRUE)
{
Type_prompt(); // display prompt
Read_command (command, parameters); // read input from the terminal
If(fork()!=0)
{
/*---parent code---*/
Waitpid(-1, statloc, 0) // wait for child process to execute
}
Else
{
/*---child code---*/
Execve (command, parameter,0); // execution of child process
}
}
Execve has 3 parameters
1st parameter name of the file to be executed
2nd parameter a pointer to the argument to the array
3rd parameter a pointer to the environment to the array
Command

cp file1 file2
 Is used to copy file1 to file2
 After the shell is forked, the child process locates and executes the file cp
 The main program of the cp contains declaration
 Main (argc, argv, envp)
1st parameter argc is count number of items in the command line
2nd parameter argv
argv[0] points the string Cp
argv[1] points the string file1
argv[2] points the string file2

3rd parameter envp (environment pointer)


Environment array is array of strings contains assignments of the form “NAME = value”
is passed to inform terminal type or home directory names to programs
Process in UNIX memory is divided up into three segments the

 Text segments
 Data segments
 Stack segments

brk is the system call used to grow data segment by allotting the new address space
where data segment is to end

Figure 14 process with three segments

Call Description
Pid = fork() Create a child process identical to parent
Pid = waitpid (pid, &statloc, 0) Wait for a child to terminate
S = execve (name, argv, environp) Replace a process coreimage
Exit(status) Terminate process execution & return status

System call for file management

Call Description
fd=open(file, how,…) Open a file for reading, writing or both
s=close(fd) Close an open file
n=read(fd,buffer,nbytes) Read data from a file into a buffer
n=write(fd,buffer,nbytes) Write data from a buffer into a file
Position=lseek(fd,offset,whence) Move the file pointer
s=stat(name,&buf) Get file’s status information

O_RDONLY – read only


O_WRONLY – write only
O_RDWR – both read and write
O_CREAT – to create a file

lseek – although most programs read and write file sequentially, for some application
need to access any part of file randomly, associated with each file a pointer that indicate
current position in the file. Lseek call changes the value of the position pointer so that
subsequent calls to read write can begin anywhere in the file.

3 parameters of lseek

1. File descriptor
2. File position
3. File position (three)
a. Beginning of the file
b. Current position of the file
c. End of file

System call for directory management

Call Description
s=mkdir(name, mode) Create a new directory
s=rmdir(name) Remove an empty directory
s=link(name1, name2) Create a new entry, name2, pointing to name1
s=unlink(name) Remove a directory entry
s=mount(special,name,flag ) Mount a file
s=unmount(special) Unmount a file

Link is to allow same file to appear under two or more names often in different
directories. Typical use is to allow the several users of the same programming team to
share a common file, with each of them having the file appear in his own directory
possibly under different name. When copies are made of a file, changes made in one will
not affect the same files with other names in different directories

Figure 15 Two directories before link

link (“/usr/SAM/MEMO”, “/usr/RAM/NOTE”)


Figure 16 Two directories after link

The file MEMO in SAM directory has now entered in RAM directory as NOTE
Every file in UNIX has a unique number, its i-number.
i-number is an index into table of i-nodes, 1 per file, telling who owns the file, where the file is
located etc…
A directory simply a file containing (i-numbers, ASCII) pairs
16 bytes (2 bytes for i-number, 14bytes - names)
Mount is merge two files systems in to one
Mount(“/dev/fd0”,”/mnt”,0)
1st parameter name of block special file for drive 0
2nd parameter is the place where it is to be mounted
3rd parameter tells whether the file system is to be mounted read-write or read only
Figure 17 Above figure File system before Below: after mount

The operating system structure


Operating system from the outside it is a programmers interface
Operating system from the inside (six different structures)

1. Monolithic system’s
OS is written as a collection of procedures, linked together in a single large executable
binary program
Each procedure is free to call any other procedure for some computation
Having thousands of procedures that can call any other without restrictions often leads
to difficulty in understanding
To solve this one first compile all individual procedures and then bind all individual file
into single executable file using system linker
In monolithic system it is possible to have some structure, the service provided by the
OS are requested by putting the parameter in a well defined place and then execute the
trap instruction.
The organization suggest a basic structure for the OS
 A main program that call upon the requested service procedure
 A set of service procedure that carry out system calls
 A set of utility procedure that help the service procedures

In this model for each system call there is a service procedure that take care of it &
execute it
The utility procedure do things that are needed by several service procedure such as
fetching data from user program

Figure 18 simple structuring model for monolithic systems

2. Layered system’s (THE – Technische Hogeschool Eindhoven system’s


designed by E.W. Dijkstra’s in Netherlands)

Layer Function
5 The operator
4 User Program
3 I/O Management
2 Operator process communication
1 Memory and drum management
0 Processor allocation and multiprogramming

Layer 0 deals with allocation of processor, switching between processes when


interrupts occurred or timer expires
It also provides basic multiprogramming of the CPU
Layer 1 did the memory management, it allocated space for process in main memory
on a 512 bit word drum for holding parts of the process (pages) for which no room in
the main memory
Software of this layer takes care of making some pages were brought in memory
whenever needed.
Layer 2 handle communication between each process and the operator console (user)
Layer 3 took care of managing the I/O devices and buffering the information streams
to & from them.
Layer 4 where the user programs are found
Layer 5 the operator process were located

3. Microkernels

Where to draw the kernel user boundary


As little as possible in kernel mode, because bugs in the kernel can bring the system
down.
User process can be set up to have less power so that a bug there may not be fatal
(serious)
Bug density depends on module size, module age & more
10 bugs / 1000 lines then for 5 million lines of codes 50,000 bugs not all are serious,
some may be incorrect error message
The basic idea of microkernel is to achieve high reliability by splitting the OS upto small,
well defined modules. Only one of which is microkernel runs in kernel mode and rest
runs in powerless ordinary user processes.
Each device driver and file system as separate user process a bug in one of these can
crash that component, but not the entire system.
Example a bug in the audio driver can cause problem to sound not the entire system
In contrast a bug in monolithic system with all the drivers in the kernel a buggy audio
driver can easily reference the invalid memory address and bring system to halt
The minix 3 microkernel is 3200 lines of codes & 800 lines of assembler for low level
functions such as cache interrupts and switching process.
C manages scheduling processes and Inter Processes Communications
35 kernel calls to allow rest of the OS to do its of the work
These kernel calls performs functions like hooking handlers to interrupts moving data
between address space and installing memory map for newly created process
Kernel call handlers labeled SYS
The device drive for the clock is also installed in the kernel because the scheduler
interacts closely with it
All other device runs on a separate user processes

Figure 149 Structure of MINIX 3 system


Outside the kernel the system is structure as 3 layers of processes all running in user
mode
Lowest layers contains device driver’s
They run in user mode there is no physical access to I/O Port space & can’t issue IO
Commands directly
In order to program IO device, the driver builds the structure & tells which value to
write in which I/O port & make a kernel call telling the kernel to write
The kernel can check to see the driver is writing from I/O it is authorized to use
Another user mode layer contains servers, server do most of the work for OS
File server manage file system,
Process manager create destroy and manage process
User program gets service from the server by sending start message for asking POSIX

(Portable Operating System Interface for uniX) system calls.

Example a process needing to read send a message to one file server telling it what to
read.
Reincarnation SERVER its job is to check if other servers & drivers are functioning
correctly.
In case if any fault is detected it automatically replaced without any user intervention.
In this way the system is self healing and achieve high reliability
The system has many restrictions limiting the power of each process.
Processes can also grant permission for other processes to have kernel access their
address space
Example a file system can grant permission to disk driver to let the kernel put a newly
read in disk block at a specific address within the file system’s address space.
The total of all these restrictions is that each driver and server has exactly the power to
do its work and nothing more thus greatly limiting the damage a bug can do
4. Client server model

Distinguish two classes of processes


The servers
The clients
Communication between them is done by message passing
To obtain service client process construct a message saying what it wants and send it to
appropriate service
The service then does the work and sends back the answer
The generalization of this idea is to have the clients and server run of different computer
connected by local or WAN

Since client communication with servers by sending message, the client need to know
whether the service is handled locally or via network to servers on a remote machine
As far as client is concerned the request are sent and replies come back
Client to server model can be used for a single machine or for a network of machines.
Example
A PC can send request for a web page to the server and the web page comes back. This
is typical use of client server model in the network

Figure 20 The Client Server model over a network


5. Virtual machines

The initial releases of OS360 were batch systems.


360 users wanted to work at terminal, so various groups decided to work to bring TSS
(time sharing system).
As a result TSS360 is designed, when it arrived in the market its functions were very
slow and the machine was very big, it has become a failure model
A new system was designed z/VM is now widely used on IBM’s current main frames, z
series are heavily used in large corporate data centers example e-commerce servers
handles 1000’s & 1000’s transactions per second

VM370

The system was originally called as CP/CMS (control program / conversational Monitor
System)
Later renamed as VM/370 based on smart observation TSS provides
Multiprogramming
Extended machine with more convenient interface than the bare H/W
The heart of the system know as virtual machine monitor runs on the bare hardware’s
& does multiprogramming for several virtual machines

Figure 15 The structure of VM/370 with CMS


They are not the extended machines like other OS, they are exact copies of bare H/W
includes

1. Kernel / user mode


2. I/O
3. Interrupts
4. And everything else the real machine has

Each virtual machine is identical to the true H/W


Each machine can run any OS that will run directly on bare H/W
Different VM can run different OS on the original VM370 s/m
Some run OS360 or one of the other large batch or transaction processing OS while
other ran a single user interactive system called CMS conversational Monitor System for
interactive time sharing users
when a CMS program executed a system call, the call was trapped to the OS in its own
virtual machine not to VM/370
CMS then issued the normal hardware I/O instructions for reading its virtual disk /
whatever needed to carry out the calls
I/O instructions were trapped by VM 370
By completely separating the functions of multiprogramming and providing an extended
machine each of the pieces could be simpler, flexible & easier to maintain

Virtual machine rediscovered

The idea of virtualization in the past few years because of new needs, new software’s &
new technologies have combined to make it a hot topic.
Many companies run their mail server, file server & FTP server on separate computers
sometimes with different operating systems
They see virtualization as a way to run them all on the same machine without having
crash of one server brings down the rests
Virtualization is also popular in web hosting world, earlier web hosting customers are
forced to choose between shared hosting & dedicated hosting

JAVA VIRTUAL MACHINE

SUN MICRO SYSTEM invented java programming , it also invent a virtual machine (a
computer architecture) called JAVA VIRTUAL MACHINE
Java compiler produces code for JVM which is then executed by a S/W JVM interpreter
An abstract computing machine, or virtual machine, JVM is a platform-independent
execution environment that converts Java bytecode into machine language
and executes it. Most programming languages compile source code directly into
machine code that is designed to run on a specific OS, such as Windows or UNIX.

A Machine Within a Machine

JVM -- a machine within a machine -- a real Javaprocessor, enabling Java bytecode to be


executed as actions or operating system calls on any processor regardless of the
operating system. For example, establishing a socket connection from a workstation to
a remote machine involves an operating system call. Since different operating systems
handle sockets in different ways, the JVM translates the programming code so that the
two machines that may be on different platforms are able to connect.

6. Exokernels

It is a program. Its job is to allocated resource to virtual machine and check attempt to
use them to make sure that no machine is trying to use some body else’s resources.
Each user is given a subset of resources. One virtual machine might get blocks 0 to 1023,
the next one might get 1024 to 2047 & so on.
Each user level virtual machine can run its own OS as on VM/370 & the Pentium virtual
8086s except that each one is restricted to using only the resources it has asked for and
been allocated
Advantage: it saves a layer of mapping, the exokernel need to keep track of which
virtual machine is assigned which resource

You might also like