Module 2 Reviewer
Module 2 Reviewer
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++
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.
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
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).
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
6
IOS ARCHITECTURE
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
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)
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.
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
BLOCK AND STACK METHODS do not limit the number or length of parameters
being passed
11
- wait event, signal event
- allocate and free memory
- Dump memory if error
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
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
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
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
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
PROCESS CONCEPTS
- An OS executes a variety of programs:
o BATCH SYSTEMS – jobs
o TIME-SHARED SYSTEMS – user programs or tasks
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.
17
4. HEAP SECTION – Dynamically allocated memory to process during its run
time.
PROCESS STATE
- As a process executes, it changes 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.
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.
20
LESSON 2: PROCESS CREATION TERMINATION AND
THREADS
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.
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.
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
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.
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
26