Os Module1
Os Module1
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
No universally accepted definition
Everything a vendor ships when you order an operating system” is good approximation
But varies wildly
Computer-System Operation A modern general-purpose computer system consists of one or more CPUs and a
number of device controllers connected through a common bus that provides access to shared memory (Figure 2).
Each device controller is in charge of a specific type of device (for example, disk drives, audio devices, or video
displays). The CPU and the device controllers can execute in parallel, competing for memory cycles. To ensure
orderly access to the shared memory, a memory controller synchronizes access to the memory.
Initially, when the computer is powered up or rebooted, it needs to have an initial program to run. This initial
program, or bootstrap program, tends to be simple. Typically, it is stored within the computer hardware in read-
only memory (ROM) or electrically erasable programmable read-only memory (EEPROM), known by the general
term firmware. It initializes all aspects of the system, from CPU registers to device controllers to memory contents.
The bootstrap program must know how to load the operating system and how to start executing that system. To
accomplish this goal, the bootstrap program must locate the operating-system kernel and load it into memory. Once
the kernel is loaded and executing, it can start providing services to the system and its users. Some services are
provided outside of the kernel, by system programs that are loaded into memory at boot time to become system
processes, or system daemons that run the entire time the kernel is running. On UNIX, the first system process is
“init,” and it starts many other daemons. Once this phase is complete, the system is fully booted, and the system
waits for some event to occur. The occurrence of an event is usually signaled by an interrupt from either the
hardware or the software. Hardware may trigger an interrupt at any time by sending a signal to the CPU, usually by
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
Interrupt Timeline
I/O Structure
After I/O starts, control returns to user program only upon I/O compl
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
After I/O starts, control returns to user program without waiting for I/
call – request to the operating system 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 Operating system indexes into I/O device table to determine device status and to
modify table entry to include interrupt
The CPU can load instructions only from memory, so any programs to run must be stored there. General-purpose
computers run most of their programs from rewritable memory, called main memory (also called random-access
memory, or RAM). Main memory commonly is implemented in a semiconductor technology called dynamic
random-access memory (DRAM). A typical instruction–execution cycle, as executed on a system with a von
Neumann architecture, first fetches an instruction from memory and stores that instruction in the instruction
register. Ideally, we want the programs and data to reside in main memory permanently. This arrangement usually
is not possible for the following two reasons: 1. Main memory is usually too small to store all needed programs
and data permanently. 2. Main memory is a volatile storage device that loses its contents when power is turned off
or otherwise lost. Thus, most computer systems provide secondary storage as an extension of main memory. The
main requirement for secondary storage is that it be able to hold large quantities of data permanently.
Storage Hierarchy
Storage systems organized in hierarchy
Speed
Cost
Volatily
Caching – copying information into faster storage system; main memory can be viewed as a last cache for
secondary storage
Important principle, performed at many levels in a computer (in hardware, operating system, software)
Information in use copied from slower to faster storage temporarily
Faster storage (cache) checked first to determine if information is there
If it is, information used directly from the cache
(fast) If not, data copied to cache and used there
Cache smaller than storage being cached
Cache management important design problem
Cache size and replacement policy
Computer-System Architecture
Most systems use a single general-purpose processor (PDAs through
mainframes) Most systems have special-purpose processors as well
Multiprocessors systems growing in use and importance
Also known as parallel systems, tightly-coupled systems
Advantages include
1. Increased throughput: increasing the number of processors, we expect to get more work done in less time. The speed-
up ratio with N processors is not N, however; rather, it is less than N. W
2. Economy of scale: Multiprocessor systems can cost less than equivalent multiple single-processor systems, because
they can share peripherals, mass storage, and power supplies. If several programs operate on the same set of data, it is cheaper
1..Asymmetric Multiprocessing
2.Symmetric Multiprocessing
A Dual-Core Design
Clustered Systems
Operating-System Operations
Interrupt driven by hardware
Software error or request creates exception or trap
Division by zero, request for operating system service
Other process problems include infinite loop, processes modifying each Other or the operating system
Dual-mode operation allows OS to protect itself and other system components
User mode and kernel mode
Mode bit provided by hardware
Provides ability to distinguish when system is running user code or kernel code
Some instructions designated as privileged, only executable in kernel mode
System call changes mode to kernel, return from call resets it to user
Transition from User to Kernel Mode
Timer to prevent infinite loop / process hogging resources
Set interrupt after specific period
Operating system decrements counter
When counter zero generate an interrupt
Set up before scheduling process to regain control or terminate program that exceeds allotted time
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
Memory Management
All data in memory before and after processing
All instructions in memory in order to execute
Memory management determines what is in memory when
Optimizing CPU utilization and computer response to users
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
MASS STORAGE 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
Varies between WORM (write-once, read-many-times) and RW (read-write)
Performance of Various Levels of Storage
De Page 10
pt. of Computer Science and Engineering
Migration of Integer A from Disk to Register
Multitasking environments must be careful to use most recent value, no matter where it is stored in the
storage hierarchy
Multiprocessor environment must provide cache coherency in hardware such that all CPUs have the
most recent value in their cache
Distributed environment situation even more complex
Several copies of a datum can exist
I/O Subsystem
One purpose of OS is to hide peculiarities of hardware devices from the user
I/O subsystem responsible for
Memory management of I/O including buffering (storing data temporarily while it is being transferred),
caching (storing parts of data in faster storage for performance), spooling (the overlapping of output of
one job with input of other jobs)
General device-driver interface
Drivers for specific hardware devices
Protection and Security
Protection – any mechanism for controlling access of processes or users to resources defined by the OS
Security – defense of the system against internal and external attacks
Huge range, including denial-of-service, worms, viruses, identity theft, theft of service
Systems generally first distinguish among users, to determine who can do what
User identities (user IDs, security IDs) include name and associated number, one per user
User ID then associated with all files, processes of that user to determine access control
Group identifier (group ID) allows set of users to be defined and controls managed, then also associated
with each process, file
Privilege escalation allows user to change to effective ID with more rights
DISTRIBUTED SYSTEMS
Computing Environments
Traditional computer
Blurring over time
Office environment
PCs connected to a network, terminals attached to mainframe or minicomputers providing batch
and timesharing
Now portals allowing networked and remote systems access to same resources
Home networks
Used to be single system, then modems
Now firewalled, networked
Client-Server Computing
Peer-to-Peer Computing
Another set of OS functions exists for ensuring the efficient operation of the system itself via resource
sharing
Resource allocation - When multiple users or multiple jobs running concurrently, resources must be
allocated to each of them
Many types of resources - Some (such as CPU cycles, main memory, and file storage) may have special
allocation code, others (such as I/O devices) may have general request and release code
Accounting - To keep track of which users use how much and what kinds of computer resources
Protection and security - The owners of information stored in a multiuser or networked computer
system may want to control use of that information, concurrent processes should not interfere with each
other
Protection involves ensuring that all access to system resources is controlled
Security of the system from outsiders requires user authentication, extends to defending external I/O
devices from invalid access attempts
If a system is to be protected and secure, precautions must be instituted throughout it. A chain is only as
strong as its weakest link.
User Operating System Interface - CLI
Command Line Interface (CLI) or command interpreter allows direct command entry
System Calls
MS-DOS execution
System Programs
System programs provide a convenient environment for program development and execution. The can be
divided into:
File manipulation
Status information
File modification
Programming language support
Program loading and execution
Communications
Application programs
Most users’ view of the operation system is defined by system programs, not the actual system calls
Provide a convenient environment for program development and execution
Some of them are simply user interfaces to system calls; others are considerably more complex
File management - Create, delete, copy, rename, print, dump, list, and generally manipulate files and
directories
Status information
Some ask the system for info - date, time, amount of available memory, disk space, number of users
Others provide detailed performance, logging, and debugging information
Typically, these programs format and print the output to the terminal or other output devices
Some systems implement a registry - used to store and retrieve configuration information
File modification
Text editors to create and modify files
Special commands to search contents of files or perform transformations of the text
Programming-language support - Compilers, assemblers, debuggers and interpreters sometimes
provided
Program loading and execution- Absolute loaders, relocatable loaders, linkage editors, and overlay-
loaders, debugging systems for higher-level and machine language
Layered Approach
The operating system is divided into a number of layers (levels), each built on top of lower layers. The
bottom layer (layer 0), is the hardware; the highest (layer N) is the user interface.
With modularity, layers are selected such that each uses functions (operations) and services of only
lower-level layers
Dept. of Computer Science and Engineering Page 19
Traditional UNIX System Structure
UNIX
UNIX – limited by hardware functionality, the original UNIX operating system had limited structuring.
The UNIX OS consists of two separable parts
Systems programs
The kernel
Consists of everything below the system-call interface and above the physical hardware
Provides the file system, CPU scheduling, memory management, and other operating-system
functions; a large number of functions for one level
Layered Operating System
Mac OS X Structure
Modules
Para-virtualization
Presents guest with system similar but not identical to hardware
Guest must be modified to run on paravirtualized hardwareF
Guest can be an OS, or in the case of Solaris 10 applications running in containers
Solaris 10 with Two Containers
Operating-System Debugging
UNIT -2
PROCESS MANAGEMENT
Process Concept
An operating system executes a variety of programs:
Batch system – jobs
Time-shared systems – user programs or tasks
Textbook uses the terms job and process almost interchangeably
Process – a program in execution; process execution must progress in sequential fashion
A process includes:
program counter
stack
data section
Process in Memory
Process State
Schedulers
Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready
queue
Short-term scheduler (or CPU scheduler) – selects which process should be executed next and
allocates CPU
Process Creation
int main()
{
pid_t pid;
/* fork another process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
exit(-1);
}
else if (pid == 0) { /* child process */
execlp("/bin/ls", "ls", NULL);
}
else { /* parent process */
/* parent will wait for the child to complete */
wait (NULL);
printf ("Child Complete");
exit(0);
}
}
Communications Models
Cooperating Processes
Independent process cannot affect or be affected by the execution of another process
Cooperating process can affect or be affected by the execution of another process
Advantages of process cooperation
Information sharing
Computation speed-up
Modularity
Convenience
Bounded-Buffer – Producer
while (true) {
/* Produce an item */
while (((in = (in + 1) % BUFFER SIZE count) == out)
; /* do nothing -- no free buffers */
buffer[in] = item;
in = (in + 1) % BUFFER SIZE;
}
Indirect Communication
Messages are directed and received from mailboxes (also referred to as ports)
Each mailbox has a unique id
Processes can communicate only if they share a mailbox
Properties of communication link
Link established only if processes share a common mailbox
A link may be associated with many processes
Each pair of processes may share several communication links
Link may be unidirectional or bi-directional
Operations
create a new mailbox
send and receive messages through mailbox
destroy a mailbox
Primitives are defined as:
send(A, message) – send a message to mailbox A
receive(A, message) – receive a message from mailbox A
Mailbox sharing
P1, P2, and P3 share mailbox A
P1, sends; P2 and P3 receive
Who gets the message?
Solutions
Allow a link to be associated with at most two processes
Allow only one process at a time to execute a receive operation
Allow the system to select arbitrarily the receiver. Sender is notified who the receiver was.
Synchronization
Message passing may be either blocking or non-blocking
Blocking is considered synchronous
Blocking send has the sender block until the message is received
Blocking receive has the receiver block until a message is available
Non-blocking is considered asynchronous
Non-blocking send has the sender send the message and continue
Non-blocking receive has the receiver receive a valid message or null
Execution of RPC
Marshalling Parameters
Benefits Responsiveness
Resource Sharing
Economy
Scalability
Multicore Programming
Multicore systems putting pressure on programmers, challenges include
Dividing activities
Balance
Data splitting Data
dependency Testing
and debugging
Multithreaded Server Architecture
User Threads
Thread management done by user-level threads librarynThree primary thread libraries:
POSIX Pthreadsl Win32 threads
Java threads
Kernel Threads
Supported by the Kernel
Examples
Windows XP/2000
Solaris
Linux
Tru64 UNIX
Mac OS X
Multithreading Models
Many-to-One
One-to-One
Many-to-Many
Many-to-One
Many user-level threads mapped to single kernel thread
Examples:
Solaris Green Threads
GNU Portable Threads
One-to-One
Each user-level thread maps to kernel thread
Examples
Windows NT/XP/2000
Linux