0% found this document useful (0 votes)
19 views26 pages

Module 2 Reviewer

Module 2 reviewer operating system
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views26 pages

Module 2 Reviewer

Module 2 reviewer operating system
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

MODULE 2

LESSON 1: OPERATING SYSTEM STRUCTURE

OPERATING SYSTEM STRUCTURE: DESIGN AND


IMPLEMENTATION

Internal structure of different Operating Systems can vary widely


•Start the design by defining goals and specifications
•Affected by choice of hardware, type of system

USER GOALS AND SYSTEM GOALS

 USER GOALS – operating system should be convenient to use,


easy to learn, reliable, safe, and fast
 SYSTEM GOALS – operating system should be easy to design,
implement, and maintain, as well as flexible, reliable, error-free, and
efficient

Important principle to separate
Policy: What will be done?
Mechanism: How to do it?
 Mechanisms determine how to do something, policies decide what will be
done
 The separation of policy from mechanism is a very important principle, it
allows maximum flexibility if policy decisions are to be changed later (example –
timer)

1
 Specifying and designing an OS is highly creative task of software
engineering

IMPLEMENTATION
 MUCH VARIATION
- Early OSes in assembly language
- Then system programming languages like Algol, PL/1
- Now C, C++

 ACTUALLY USUALLY A MIX OF LANGUAGES


- Lowest levels in assembly
- Main body in C
- Systems programs in C, C++, scripting languages like PERL,
Python, shell scripts

 MORE HIGH-LEVEL LANGUAGE EASIER TO PORT TO OTHER


HARDWARE
- But slower

EMULATION – can allow an OS to run on non-native hardware.

OPERATING SYSTEM STRUCTURES / ARCHITECTURE

1. MONOLITHIC STRUCTURE – is to run the entire OS as a


single program in kernel mode.
- The OS is written as a collection of procedures, linked together
into a single large executable binary program.

2
This structure suggests a basic structure for the operating system:
1. A main program that invokes the requested service procedure.
2. A set of service procedures that carry out the system calls.
3. A set of utility procedures that help the service procedures.

MONOLITIHIC STRUCTURE DIAGRAM

 ONE SERVICE PROCEDURE – In monolithic model, for each


system call there is one service procedure that takes care of it and
executes it.
 UTILITY PROCEDURE – do things that are needed by several
service procedures such as fetching data from user programs.

SIMPLE / MONOLITHIC STRUCTURE – MS DOS

MS-DOS – written to provide the most functionality in the least space.


- Although MS-DOS has some structure, its interfaces and levels
of functionality are not well separated.

3
NON-SIMPLE STRUCTURE – UNIX
UNIX – limited by hardware functionality, the original UNIX OS has limited
structuring.
- The UNIX consists of 2 separable parts:
1. SYSTEMS PROGRAMS
2. THE KERNEL

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

2.LAYERED APPROACH – The OS 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 interface.
- With modularity, layers are selected such that each uses functions
(operations) and services of only lower-level layers

4
 THE SYSTEM – built at the TECHNISCHE HOGESCHOOL
EINDHOVEN in the Netherlands by E.W. DIJKSTRA (1968) and his
students.
- Was a simple batch system for a Dutch computer,
- the Electrologica X8, which had 32K of 27-bit words (bits were
expensive back then).

3. MICROKERNEL SYSTEM STRUCTURE – The basic idea


behind the microkernel design is to achieve high reliability by
splitting the OS up into small, well-defined modules, only one of
which—the microkernel—runs in kernel mode and the rest run as
relatively powerless ordinary user processes.

COMMUNICATION takes place between user modules using


message passing

BENEFITS:
- Easier to extend a microkernel
- Easier to port the operating system to new architectures
- More reliable (less code is running in kernel mode)
- More secure

5
4. MODULES / MODULAR STRUCTURE – Many modern OS
implement LOADABLE KERNEL MODULES
- Uses object-oriented approach
- Each core component is separate
- Each talks to the others over known interfaces
- Each is loadable as needed within the kernel
- Overall, similar to layers but with more flexible
- Ex : Linux, Solaris, etc

5. HYBRID SYSTEMS / STRUCTURE – Most modern OS are


actually not one pure model

 HYBRID – combines multiple approaches to address performance,


security, usability needs
 LINUX & SOLARIS KERNELS – in kernel address space, so
monolithic, plus modular for dynamic loading of functionality.
 WINDOWS – mostly monolithic, plus microkernel for different
subsystem personalities.

APPLE MAC OS X HYBRID, LAYERED


- Aqua UI plus Cocoa programming environment
 KERNEL EXTENSIONS - consisting of Mach microkernel
and BSD Unix parts, plus I/O kit and dynamically loadable
modules

6
IOS ARCHITECTURE

APPLE MOBILE OS FOR IPHONE, IPAD


- Structured on MAC OS X, added functionality
- Does not run OS X applications natively

 COCOA TOUCH – Objective C API for developing


 MEDIA SERVICES – Layer for graphics, audio, video
 CORE SERVICES – provides cloud computing, databases
 CORE OS – based on Mac OS X kernel

ANDROID OS ARCHITECTURE
 Developed by Open Handset (mostly Google)
- Open Source
 Similar stack to IOS
 Based on Linux kernel but modified
- Provides process, memory, device-driver management
- Adds power management
 Runtime environment includes core set of libraries and Dalvik virtual
machine
- Apps developed in Java plus Android API
- Java class files compiled to Java bytecode then translated to executable
than runs in Dalvik VM
 Libraries include frameworks for web browser (webkit), database (SQLite),
multimedia, smaller libc

7
OPERATING SYSTEM DEBUGGING

DEBUGGING – is finding and fixing errors, or bugs


- OS generate log files containing error information
- Failure of an application can generate core dump file capturing memory of the
process
- Operating system failure can generate crash dump file containing kernel
memory
- Beyond crashes, performance tuning can optimize system performance

KERNIGHAN’S LAW: “Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough
to debug it.”

PERFORMANCE TUNING
- Improve performance by removing bottlenecks
- OS must provide means of computing and displaying measures of system
behavior
- For example, “top” program or Windows Task Manager

8
LESSON 2: SYSTEM CALLS AND SYSTEM PROGRAM

SYSTEM CALLS
- Programming interface to the services provided by the
OS.
- Written in a high-level language (C or C++)
- Mostly accessed by programs via a high-level Application
Programming Interface (API) rather than direct system call
use
- Three most common APIs are:
o Win32 API for Windows
o POSIX API for POSIC based systems(virtually all
versions of UNIX, LINUX, and Mac OS X) , and
o JAVA API for Jaava virtual machine (JVM)

SYSTEM CALL EXAMPLE


- If a process is running a user program in user mode and needs a system service,
such as reading data from a file, it has to execute a trap instruction to transfer
control to the operating system.
- The operating system then figures out what the calling process wants by
inspecting the parameters.
- Then it carries out the system call and returns control to the instruction following
the system call.
- In a sense, making a system call is like making a special kind of procedure call—
only system calls enter the kernel and procedure calls do not.

9
STEPS IN SYSTEM CALLS

- System calls are performed in a series of steps. To make this concept clearer,
- In preparation for calling the read library procedure, which actually makes the read
system call, the calling program first prepares the parameters, for instance by storing
them in a set of registers that by convention are used for parameters.
- The first and third parameters are passed by value, but the second parameter is a
reference, meaning that the address of the buffer is passed, not the contents of the
buffer. Then comes the actual call to the library procedure (step 4). This instruction is the
normal procedure-call instruction used to call all procedures.

SYSTEM CALL IMPLEMENTATION

- Typically, a number associated with each system call.

SYSTEM INTERFACE – maintains a table indexed according to these numbers/


- Invokes the intended system call in OS kernel and returns status of system call and any
return values.
- The caller need know nothing about how the system call is implemented
- Just needs to obey API and understand what OS will do as a result call
- Most details of OS interface hidden from programmer by API
- Managed by run-time support library (set of functions built into libraries included with
compiler)

API – SYSTEM CALL – OS RELATIONSHIP

10
SYSTEM CALL PARAMETER PASSING
- Often, more information is required than simply identity of desired system call
- Exact type and amount of information vary according to OS and call
- Three general methods used to pass parameters to the OS
- Simplest: pass the parameters in registers
- In some cases, may be more parameters than registers

PARAMETERS stored in a block, or table, in memory, and address of block passed as


a parameter in a register

- This approach taken by Linux and Solaris


- Parameters placed, or pushed, onto the stack by the program and popped off the
stack by the operating system

BLOCK AND STACK METHODS do not limit the number or length of parameters
being passed

Parameter Passing via Table

TYPES OF SYSTEM CALLS


1. PROCESS CONTROL
- create process, terminate process
- end, abort
- load, execute
- get process attributes, set process attribute
- wait for time

11
- wait event, signal event
- allocate and free memory
- Dump memory if error

DEBUGGER – for determining bugs, single step execution


LOCKS – for managing access to shared data between processes.

2. FILE MANAGEMENT
- create file, delete file
- open, close file
- read, write, reposition
- get and set file attributes

3. DEVICE MANAGEMENT
- request device, release device
- read, write, reposition
- get device attributes, set device attributes
- logically attach or detach devices

4. INFORMATION MAINTENANCE
- get time or date, set time or date
- get system data, set system data
- get and set process, file, or device attributes

5. COMMUNICATIONS
- create, delete communication connection
- send, receive messages if message passing model to host name or process
nameFrom client to server

12
SHARED-MEMORY MODEL create and gain access to memory regions
- transfer status information
- attach and detach remote devices

6. PROTECTION
- Control access to resource
- Get and set permissions
- Allow and deny user access

STANDARD C LIBRARY EXAMPLE

C PROGRAM – invoking printf() library call, which call write() system call.

Example:

MS-DOS
- Single-tasking
- Shell invoked when system booted

13
- Simple method to run program No process created
- Single memory space
- Loads program into memory, overwriting all but the kernel
Program exit -> shell reloaded

FREEBSD
- Unix variant
- Multitasking

USER LOGIN -> invoke user’s choice of shell


SHELL - executes fork() system call to create process Executes exec() to load
program into process
- Shell waits for process to terminate or continues with user commands
- •rocess exits with:code = 0 – no error
- code > 0 – error code

SYSTEM PROGRAM
- provide a convenient environment for program development and
execution. They can be divided into:

o File manipulation
o Status information sometimes stored in a File modification
o Programming language support
o Program loading and execution
o Communications
o Background services
o Application program

- Most users’ view of the operation system is defined by system


programs, not the actual system calls

14
- 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
COMMUNICATIONS - Provide the mechanism for creating virtual
connections among processes, users, and computer systems
- Allow users to send messages to one another’s screens, browse web
pages, send electronic-mail messages, log in remotely, transfer files
from one machine to another
BACKGROUND SERVICES

15
- Launch at boot time
- Some for system startup, then terminate
- Some from system boot to shutdown
- Provide facilities like disk checking, process scheduling, error logging,
printing
- Run in user context not kernel context
- Known as services, subsystems, daemons

APPLICATION PROGRAMS
- Don’t pertain to system
- Run by user
- Not typically considered part of OS
- Launched by command line, mouse click, finger poke

16
MODULE 3

LESSON 1: PROCESS CONCEPTS

PROCESS CONCEPTS
- An OS executes a variety of programs:
o BATCH SYSTEMS – jobs
o TIME-SHARED SYSTEMS – user programs or tasks

JOB AND PROCESS – almost interchangeably


PROCESS – a program in execution
- process execution must progress in sequential fashion

PROGRAM – is passive entity stored on disk (executable file)


PROCESS – is active.

EXECUTION OF PROGRAM – started via GUI mouse clicks, command line entry
of its name, etc
- One program can be several processes
- Consider multiple users executing the same program.

WHAT DOES A PROCESS LOOK LIKE IN MEMORY?

1. TEXT SECTION – A process, sometimes known as the Text Section, also


includes the current activity represented by the value of the program counter.
2. STACK – Contains the temporary data, such as function parameters, returns
addresses, and local variables.
3. DATA SECTION – Contains the global variable.

17
4. HEAP SECTION – Dynamically allocated memory to process during its run
time.

PROCESS STATE
- As a process executes, it changes state.

 NEW – The process is being created.


 RUNNING – Instructions are being executed.
 WAITING – The process is waiting for some event to occur.
 READY – The process is waiting to be assigned to a processor.
 TERMINATED – The process has finished execution.
 SUSPENDED READY – When the ready queue becomes full, some
processes are moved to this state.
 SUSPENDED BLOCK – When waiting queue becomes full.

DIAGRAM OF PROCESS STATE

18
HOW DOES A PROCESS MOVE FROM ONE STATE TO OTHER STATE?
- A process can move between different states in an operating system
based on its execution status and resource availability.
Examples:
New to Ready: When a process is created, it is in a new state. It
moves to the ready state when the operating system has allocated
resources to it and it is ready to be executed.
Ready to Running: When the CPU becomes available, the operating
system selects a process from the ready queue depending on various
scheduling algorithms and moves it to the running state.

PROCESS CONTROL BLOCK (PCB)


o TASK CONTROL BLOCK – Information associated with each process.
o PROCESS STATE – running, waiting, etc.
o PROGRAM COUNTER – Location of instruction to next execute.
o CPU REGISTERS – Contents of all process-centric registers
o CPU SCHEDULING INFORMATION – Priorities, scheduling queue
pointers.
o MEMORY-MANAGEMENT INFORMATION – Memory allocated to the
process.
o ACCOUNTING INFORMATION – CPU used, clock time elapsed since
start, time limits.
o I/O STATUS INFORMATION – I/O devices allocated to process, list of open
files.

CPU SWITCH FROM PROCESS TO PROCESS

19
CONTEXT SWITCHING
- The process of saving the context of one process and loading
the context of another process is known as context switching.
- In simple terms, it is like loading and unloading the process from
running state to ready state.
Context switching happens when:
- When a high-priority process comes to ready state (i.e. with higher
priority than the running process)
- An interrupt occurs.
- User and kernel mode switch (though, this is not necessary)
- Preemptive CPU scheduling is used.

MODE SWITCH – Occurs when CPU privilege level is changed, for


example when a system call is made or a fault occurs. The kernel works in
a more privileged mode than a standard user task.
- typically occurs for a process context switch to occur. Only the
kernel can cause a context switch.
- If a user process wants to access things which are only accessible to
the kernel, a mode switch must occur. The currently executing
process need not to be changed during a mode switch.

CPU-BOUND VERSUS I/O-BOUND PROCESSES

1. CPU BOUND – process requires more CPU time or spends more


time in the running state
2. I/O BOUND – process requires more I/O time and less CPU
time.
- Spends more time in the waiting state.

20
LESSON 2: PROCESS CREATION TERMINATION AND
THREADS

PROCESS CREATION – A process may be created in the system


for different operations. Some of the events that lead to process creation
are:
- User request for process creation
- System initialization
- Batch job initialization
- Execution of a process creation system call by a running process.

STEPS IN PROCESS CREATION

FORK() – A process may be created by another process using fork().


- The CREATING PROCESS is called the parent process
- the CREATED PROCESS is called the child process.

21
PROCESS TERMINATION – Occurs when the exit system is called.
A process usually exits after its completion but sometimes there are
cases where the process aborts execution and terminates.
- Process executes last statement and then asks the operating system
to delete it using the exit() system call.

- Parent may terminate the execution of children processes using the


abort() system call.

CAUSES OF PROCESS TERMINATION

- When a parent process is terminated, its child process is also


terminated. This happens when a child process cannot exist without
its parent process.
- If a process needs additional memory more than what the system
allocated, termination happens because of memory scarcity
- A process tries to access a resource that is not allowed to use
- If the process fails to allocate a resource within the allotted time
- When a parent process requests the termination of its child process.
- The task is no longer required or needed

PROCESS THREADS

THREA.
D – Is a basic unit of CPU utilization.
- It is a flow of control within a process.
- Is a path of execution within a process code, with its own program counter that
keeps track of which instruction to execute next, system registers which hold its
current working variables, and a stack which contains the execution history.

22
- also provide a suitable foundation for parallel execution of applications on shared
memory multiprocessors.

MULTITHREADED SERVER ARCHITECTURE


CLIENT - > SERVER -> THREAD

BENEFITS OF THREADS
1. RESPONSIVENESS – may allow continued execution if part of
process is blocked, especially important for user interfaces
2. RESOURCE SHARING – threads share resources of process, easier
than shared memory or message passing
3. ECONOMY – cheaper than process creation, thread switching lower
overhead than context switching
4. SCALABILITY – process can take advantage of multiprocessor
architectures

SINGLE AND MULTITHREADED PROCESSES

23
1. MANY TO ONE
- Many user level threads mapped to single kernel thread
- One thread blocking causes all to block
- Multiple threads may not run in parallel on multicore system because only one
may be in kernel at a time.
- Few systems currently use this model

Examples:
Solaris Green Threads
GNU Portable Threads

2. ONE-TO-ONE
- Each user-level thread maps to kernel thread
- Creating a user-level thread creates a kernel thread
- More concurrency than many-to-one
- Number of threads per process sometimes restricted due to overhead

Examples:
Windows
Linux
Solaris 9 and later

3. MANY-TO-MANY MODEL
- threads to be mapped to many kernel threads
- Allows the operating system to create a sufficient number of kernel
threads
- Solaris prior to version 9
- Windows with the ThreadFiber package

24
4. TWO-LEVEL MODEL
- Similar to M:M, except that it allows a user thread to be bound to
kernel thread
Examples:

IRIX
HP-UX
Tru64 UNIX
Solaris 8 and earlier

WINDOWS THREADS

- Windows implements the Windows API – primary API for Win 98, Win NT, Win
2000, Win XP, and Win 7
- Implements the one-to-one mapping, kernel-level
- Each thread contains:
o A thread id
o Register set representing state of processor
o Separate user and kernel stacks for when thread runs in user mode or kernel
mode
o Private data storage area used by run-time libraries and dynamic link libraries
(DLLs)

CONTEXT – The register set, stacks, and private storage of the thread.

The primary data structures of a thread include:

1. ETHREAD (EXECUTIVE THREAD BLOCK) – Includes pointer to


process to which thread belongs and to KTHREAD, in kernel space.
2. KTHREAD (KERNEL THREAD BLOCK) – Scheduling and KTHREAD
(kernel thread block) – scheduling and synchronization info, kernel-mode stack,
pointer to TEB, in kernel space.
3. TEB (THREAD ENVIRONMENT BLOCK) – Thread id, user mode stack,
thread local storage, in user space.

LINUX THREADS
- Linux refers to them as tasks rather than threads

25
- Thread creation is done through clone() system call
CLONE() - allows a child task to share the address space of the parent task
(process)
- Flags control behavior

1. CLONE_FS – File-system information is shared.


2. CLONE_VM – The same memory space is shared.
3. CLONE_SIGHAND – Signal handlers are shared.
4. CLONE_FILES – The set of open files is shared.

26

You might also like