Operating Systems 1
Operating Systems 1
Course Syllabus
Introduction to OS.
Operating System Structures.
Processes.
Threads.
CPU Scheduling.
Process Synchronization.
Deadlocks.
Main Memory Management.
Computer System Structure
Computer system can be divided into four components:
Operating system
Controls the use of hardware among various applications and users.
Application programs
Define the ways in which the system resources are used to solve the computing
problems for the users.
Example: Word processors, compilers, web browsers, database systems, video
games.
Users
People, machines, other computers.
Cont…
What is an Operating System?
User View
System View
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.
Cont…
A more common definition, and the one that we usually follow, is that
The operating system is the one program running at
all times on the computer memory usually called the kernel.
Along with the kernel, there are two other types of programs:
• System Programs, which are associated with the operating system but are not
necessarily part of the kernel.
• Application Programs, which include all programs not associated with the
operation of the system.
Computer Startup
1. Power-on Self-Test (POST): The computer's BIOS (i.e., Basic Input/ Output system) or
UEFI (i.e., Unified Extensible Firmware Interface) firmware performs hardware checks.
2. Bootloader: The BIOS/UEFI loads the bootstrap from the boot device (e.g., hard drive,
SSD).
3. Bootstrap Execution: The bootstrap loads the operating system kernel into the memory.
4. Kernel Initialization: The kernel initializes device drivers, memory management, and
system services.
5. Operating System Load: The kernel loads the operating system's core components.
Cont…
How a modern computer works..
Multiprocessing Architecture
Advantages include:
• Increased throughput: by increasing the number of processors, we expect to get
more work done in less time.
• Economy of scale: Multiprocessor systems can cost less than equivalent multiple
single-processor systems, because they can have the same hardware resources.
Multiprocessor System:
1. Multiple processors (CPUs) connected together.
2. Each processor has its own memory and I/O systems.
3. Processors communicate through interconnects (bus, network).
Example: Distributed Systems.
A bit, called the mode bit, is added to the hardware of the computer to indicate
the current mode: kernel (0) or user (1).
• 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.
Virtualization
User interface (UI): Almost all operating systems have a user interface
• Varies between Command-Line (CLI), Graphics User Interface (GUI), Batch.
Program Execution: The system must be able to load a program into memory
and to run that program and end execution
I/O Operations: A running program may require I/O, which may involve a file
or an I/O device.
Accounting: To keep track the users, how much and what kinds of computer
resources they are used.
Three most common APIs are Win32 API for Windows, POSIX API for
POSIX-based systems (including virtually all versions of UNIX, Linux, and
Mac OS).
Cont…
Example: System call sequence to copy the contents of one file to another file.
Cont…
Cont…
C program invoking printf() library call, which calls write() system call.
Processes Concept
A program is a passive entity such as the file that contains the list of
instructions stored on a disk always referred to as an executable file.
Processes include not only a text but also include a set of resources such as
open files and pending signals. Processes also contain internal kernel data,
process state, an address space, and a data section.
Cont…
Text Section: the program code. This is typically read-only, and might be
shared by a number of processes.
Data Section: containing global variables.
Heap: containing memory dynamically allocated during run time.
Stack: containing temporary data.
• Function parameters, return addresses, local variables.
Cont…
Process in Memory.
Process Control Block (PCB)
Program Counter
• Location of instruction to next execute.
CPU Registers
• Contents of all process-centric registers.
Cont…
Memory-Management Information
• Memory allocated to the process.
Accounting Information
• CPU used, clock time elapsed since start, time limits.
Medium-term Scheduler
• Can be added if degree of multiple programming needs to decrease.
• Remove process from memory, store on disk, bring back in from disk to continue
execution: swapping.
Interprocess Communication
It shares with other threads belonging to the same process its code section,
data section, and other operating-system resources, such as open files and
signals.
Cont…
Let's say, for example, a program is not capable of drawing pictures while
reading keystrokes. The program must give its full attention to the keyboard
input lacking the ability to handle more than one event at a time.
The ideal solution to this problem is the seamless execution of two or more
sections of a program at the same time. Threads allows us to do this.
Cont…
• A web browser might have one thread display images or text while another thread
retrieves data from the network, for example.
• A word processor may have a thread for displaying graphics, another thread for
responding to keystrokes from the user, and a third thread for performing spelling and
grammar checking in the background.
Cont…
Support for threads may be provided either at the user level, for user threads,
or by the kernel, for kernel threads.
User threads are supported above the kernel and are managed without kernel
support, whereas kernel threads are supported and managed directly by the
operating system.
Ultimately, a relationship must exist between user threads and kernel threads.
We look at three common models:
• The one-to-one model,
• The many-to-one model, and
• The many-to-many model.
One-to-One Model
The one-to-one model maps each user thread to a kernel thread. It also allows
multiple threads to run in parallel on multiprocessors.
The only drawback to this model is that creating a user thread requires creating
the corresponding kernel thread.
Because the overhead of creating kernel threads can burden the performance of
an application, most implementations of this model restrict the number of
threads supported by the system.
Many-to-One Model
Many-to-Many Model
Economy- cheaper than process creation, thread switching lower overhead than
context switching.