Introduction To OS
Introduction To OS
1
Block Diagram of a Computer (Logical)
2
Operating System (OS)
• What do you do with just computer hardware?
– If someone gives you a computer with no software
whatsoever, how do you get it to do anything?
– You write a program that runs on the hardware
3
Without an OS
• Each program runs directly on the hardware
• Each program must do everything
• Each program needs to know the details of the hardware and
how to use it
• If the hardware changes, the program must change as well
• The hardware supports only one program at a time - each
user must wait until the previous program is done to “share”
the hardware with other users.
• Writing programs is incredibly complex and expensive
• OS is like an extended machine to provide a better interface
for convenience.
4
Four Components of a Computer System:
5
Computer System Structure
❑ Operating system
■ Controls and coordinates use of hardware among various
applications and users
❑ Users
■ People, machines, other computers
6
Operating System (OS)
• Integrated set of programs that controls the resources of a
computer system
• Provides its users with an interface which is more convenient
to use than bare machine
• Directly sits on top of the hardware and controls it
• Manages computer hardware
• Provides a basis for application programs
• Acts as an intermediary between computer user and
computer hardware
7
Introduction
• “An operating system is similar to a government. Like a
government, it performs no useful function by itself. It simply
provides an environment within which other programs can do
useful work”
8
Views of an Operating System
• Resource Allocator
– Operating system manages or allocates resources
– What resources?
• CPU time, RAM Memory, disk & other I/O devices, interrupt
numbers (IRQ’s), files, network ports & sockets, and other
software resources
– Who uses the resources?
• Resource users: One or more user processes & threads
• Control Program
– Operation and control of hardware devices
– Implements security and protection
– Execution of user program to prevent errors and prevent improper
use of the computer
9
Goals of an OS
⚫ Execute user programs and make solving user
problems easier
⚫ Make the computer system convenient to use
⚫ Use the computer resources in an efficient
manner
⚫ Ability to evolve
⚫ Can you think of reasons which make evolution
necessary?
⚫ H/W changes, new services, fixes
⚫ Different design goals for different OS
⚫ Mainframes, PC, Handheld
10
The Role of an OS
• A computer is a set of resources for the movement, storage, and
processing of data.
• The OS is responsible for managing these resources.
11
Operating System as Software
12
OS as Resource Manager
13
Common Tasks by OS
14
Basic function of OS:
• Process Management
• File Management
15
1. 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
16
Process Management Activities
The operating system is responsible for the following activities in connection
with process management:
17
2. Main Memory Management
■ Main memory -array of words/bytes
❑ 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
18
3. Secondary Storage Management
■ Main memory is small and volatile
■ Secondary storage is large and nonvolatile
19
4. I/O Subsystem management
■ One purpose of OS is to hide peculiarities of hardware devices from the user
✔ spooling (the overlapping of output of one job with input of other jobs)
20
5. File 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
21
FS Management Activities
❑ Creating and deleting files
❑ Creating and deleting directories
❑ Supporting primitives for manipulating files and directories
❑ Mapping files onto secondary storage
❑ Backing up files on stable (non-volatile) storage media
i
OS Services
A view of OS services
23
User – OS Interface
• GUI
– Graphical User Interface
– Desktop, icons, mouse
• CLI
– Command Line Interface
– Allows direct command entry
– Sometimes implemented in kernel, sometimes by systems
program
– Command interpreter
– Windows: Command shell
– UNIX/LINUX: Terminal – bash, ksh, csh: shells
– Built-in commands vs external commands
System Calls
• There are two modes in the computer system one is user mode and
another is kernel mode.
• In computer system there are different types of processes that are running
on a computer system.
• When a user runs an application it is said to be in user mode or computer
is in user mode.
• When there is a requirement of hardware resource, the process sends a
request to the kernel to get the process access and then computer enters
in kernel mode.
• These requests are sent by using system call.
• The computer switches between these two mode frequently. Whenever
the task is completed the computer goes back to the user mode from
kernel mode. This mode of transition is called context switching.
25
System Calls
❑ User programs are not allowed to access system resources
directly. They must ask the OS to do that for them.
26
Dual Mode Operation
■ 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 X), and Java API for the Java virtual machine (JVM)
28
API
• An API is a set of functions provided by an operating
system or other system software.
• An application program calls the functions to request the
services.
• An API clearly defines how to call functions and what the
results are. (API is specification, not implementation)
• Examples: APIs for file system, graphics user interface,
networking, etc
29
Types of System Calls : There are 5 different categories of system calls –
1. Process control: end, abort, create, terminate, allocate and free
memory.
2. File management: create, open, close, delete, read file etc.
3. Device management
4. Information maintenance
5. Communication
API – System Call – OS Relationship
31
Standard C Library Example
■ C program invoking printf() library call, which calls write() system call
32
Examples of Windows and Unix System Calls
33