NETW 3005 System Structure and Processes Last lecture

  • Slides: 26
Download presentation
NETW 3005 System Structure and Processes

NETW 3005 System Structure and Processes

Last lecture • History and types of operating systems: – batch systems, multiprogramming systems,

Last lecture • History and types of operating systems: – batch systems, multiprogramming systems, time sharing systems, etc. • Operating system tasks: – process management, storage management, I/O device management, user interface. NETW 3005 (Operating Systems) Lecture 02 - System Structure & Processes 2

This lecture • Hierarchical Structure in Operating Systems • System calls and interrupts •

This lecture • Hierarchical Structure in Operating Systems • System calls and interrupts • Representing processes in Operating Systems • Overview of process scheduling. NETW 3005 (Operating Systems) Lecture 02 - System Structure & Processes 3

Layered Approach • The operating system is divided into a number of layers (levels),

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

Hierarchical structure in OS • An operating system must be carefully designed and one

Hierarchical structure in OS • An operating system must be carefully designed and one central requirement is modularity. • Distinction between system programs, application programs and kernel programs • Different operating systems enforce different degrees of modularity. • Ideally you want to oblige all system and application programs to talk to the hardware via the kernel. NETW 3005 (Operating Systems) Lecture 02 - System Structure & Processes 5

MS-DOS Application programs System programs Kernel operations Device drivers NETW 3005 COSC 243 (Operating

MS-DOS Application programs System programs Kernel operations Device drivers NETW 3005 COSC 243 (Operating Systems) Terminal drivers Memory manager Lecture 02 - System Structure & Processes 6

System calls • Programming interface to the services provided by the OS • Written

System calls • Programming interface to the services provided by the OS • Written in the same language as kernel (typically C or c++). • The set of system calls is termed the programmer interface to the system. • Example : • Win 32 API for Windows • POSIX API for UNIX , JAVA API for JVM NETW 3005 (Operating Systems) Lecture 02 - System Structure & Processes 7

Talking to the kernel: system calls System Program ‘‘read from the keyboard’’ ‘‘open a

Talking to the kernel: system calls System Program ‘‘read from the keyboard’’ ‘‘open a file’’ ‘‘write to the screen’’ Kernel Hardware NETW 3005 (Operating Systems) Lecture 02 - System Structure & Processes 8

Types of system call • Process control – create, terminate, suspend, resume, abort. •

Types of system call • Process control – create, terminate, suspend, resume, abort. • File manipulation – open, close, read, write • Device manipulation – request, release, read, write. • Housekeeping – get/set time or date – get/set attributes (process, device, file) • Communications – set up link, – send/receive message NETW 3005 (Operating Systems) Lecture 02 - System Structure & Processes 9

Examples of Windows and Unix System Calls

Examples of Windows and Unix System Calls

System Call Implementation • Typically, a number associated with each system call – System-call

System Call Implementation • Typically, a number associated with each system call – System-call interface maintains a table indexed according to these numbers • The system call interface invokes the intended system call in OS kernel and returns status of the 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

API – System Call – OS Relationship

Process Concept • Process – a program in execution; process execution must progress in

Process Concept • Process – a program in execution; process execution must progress in sequential fashion • PCB stores Information associated with each process

Components of a process • Code section: section the program code itself • Data

Components of a process • Code section: section the program code itself • Data section: section any global variables used by the program • Process stack: stack any local variables currently being used (subroutine parameters, return addresses, etc. ) • Program counter: counter a pointer to some place in the program code. • Contents of CPU registers • Memory management information • Accounting information: information who owns the process, how long it’s been running, how much CPU time it’s used so far, etc. NETW 3005 (Operating Systems) Lecture 02 - System Structure & Processes 14

Process State • As a process executes, it changes state – new: The process

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

Diagram of Process State

Diagram of Process State

CPU Switch From Process to Process

CPU Switch From Process to Process

Process Scheduling • Maximize CPU use, quickly switch processes onto CPU for time sharing

Process Scheduling • Maximize CPU use, quickly switch processes onto CPU for time sharing • Process scheduler selects among available processes for next execution on CPU • Maintains scheduling queues of processes – Job queue – set of all processes in the system – Ready queue – set of all processes residing in main memory, ready and waiting to execute – Device queues – set of processes waiting for an I/O device – Processes migrate among the various queues

Types of scheduler • Long-term scheduler (batch systems): decides which jobs loaded onto the

Types of scheduler • Long-term scheduler (batch systems): decides which jobs loaded onto the disk should be moved to main memory. • Short-term scheduler (a. k. a. CPU scheduler): chooses how to allocate the CPU between the processes which are ready to execute. NETW 3005 (Operating Systems) Lecture 02 - System Structure & Processes 19

Representation of Process Scheduling n Queueing diagram represents queues, resources, flows

Representation of Process Scheduling n Queueing diagram represents queues, resources, flows

Operations on Processes • System must provide mechanisms for: – process creation, – process

Operations on Processes • System must provide mechanisms for: – process creation, – process termination, – and so on as detailed next

Process Creation • Parent process create children processes, which, in turn create other processes,

Process Creation • Parent process create children processes, which, in turn create other processes, forming a tree of processes • Generally, process identified and managed via a process identifier (pid) • Resource sharing options – Parent and children share all resources – Children share subset of parent’s resources – Parent and child share no resources • Execution options – Parent and children execute concurrently – Parent waits until children terminate

A Tree of Processes in Linux

A Tree of Processes in Linux

Process Creation (Cont. ) • UNIX examples – fork() system call creates new process

Process Creation (Cont. ) • UNIX examples – fork() system call creates new process – exec() system call used after a fork() to replace the process’ memory space with a new program

Process Termination • Process executes last statement and then asks the operating system to

Process Termination • 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. • The parent process may wait for termination of a child process by using the wait()system call.

Next Lecture Threads and Data Sharing

Next Lecture Threads and Data Sharing