Operating Systems Processes ENCE 360.

Slides:



Advertisements
Similar presentations
Operating Systems COMP 4850/CISG 5550 Processes Introduction to Threads Dr. James Money.
Advertisements

Chapter 6 Limited Direct Execution
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972.
Operating System I Processes. F “A program in execution” F Modern computers allow several at once –“pseudoparallelism” A B C Program Counter A B C B A.
Processes CSCI 444/544 Operating Systems Fall 2008.
Operating Systems Processes (Ch 4.1). Processes “A program in execution” Modern computers allow several at once –“pseudoparallelism” A B C Program Counter.
Operating Systems Processes (Ch 3.1). Processes “A program in execution” Modern computers allow several at once –“pseudoparallelism” A B C Program Counter.
1 CS 333 Introduction to Operating Systems Class 2 – OS-Related Hardware & Software The Process Concept Jonathan Walpole Computer Science Portland State.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Operating Systems Processes (Ch 4.1). Processes “A program in execution” Modern computers allow several at once –“pseudoparallelism” A B C Program Counter.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Process Description and Control A process is sometimes called a task, it is a program in execution.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Review. Questions F What are two functions of an OS? F What “layer” is above the OS? F What “layer” is below the OS?
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
System Calls 1.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
Chapter 3 Process Description and Control
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
Operating System Structure A key concept of operating systems is multiprogramming. –Goal of multiprogramming is to efficiently utilize all of the computing.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Chapter 6 Limited Direct Execution Chien-Chung Shen CIS/UD
1.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 1: Introduction What Operating Systems Do √ Computer-System Organization.
Processes and threads.
Chapter 3: Processes.
Process Management Process Concept Why only the global variables?
Protection of System Resources
Mechanism: Limited Direct Execution
CS 3305 System Calls Lecture 7.
Chapter 3: Processes.
Intro to Processes CSSE 332 Operating Systems
Processes in Unix, Linux, and Windows
Structure of Processes
Processes in Unix, Linux, and Windows
More examples How many processes does this piece of code create?
Processes in Unix, Linux, and Windows
Operating Systems Lecture 6.
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Process & its States Lecture 5.
Chapter 3: Processes.
Process Description and Control
Operating Systems Processes (Ch 4.1).
Processes Hank Levy 1.
Operating Systems Lecture 3.
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Lecture 6: Multiprogramming and Context Switching
Chapter 3: Processes.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
CS510 Operating System Foundations
Process Description and Control in Unix
Processes Hank Levy 1.
Process Description and Control in Unix
Operating Systems Processes (Ch 2.1).
Presentation transcript:

Operating Systems Processes ENCE 360

MODERN OPERATING SYSTEMS (MOS) Outline Motivation Control block Switching Control Chapter 2 MODERN OPERATING SYSTEMS (MOS) By Andrew Tanenbaum Chapter 4 OPERATING SYSTEMS: THREE EASY PIECES  By Arpaci-Dusseau and Arpaci-Dusseau

The Problem Remember “CPU” program from day 1? Each ran as if was only program on computer A B C D THE CRUX OF THE PROBLEM: HOW TO PROVIDE ILLUSION OF MANY CPUS? Few physical CPUs available, so how can OS provide illusion of nearly-endless supply of said CPUs?

The Solution – The Process “A program in execution” Running several at once provides pseudo-parallelism B A C Time Time-sharing A A B C B Program Counter Conceptual View C Low-level machinery (mechanisms) Answer question of how. E.g., how to keep program context High-level intelligence (policies) Answer question of which. E.g., which process to run Note: good design to separate!

Process States Consider the shell command: What is this command doing? cat /etc/passwd | grep claypool What is this command doing? How many processes are involved?

Process States Consider the shell command: cat /etc/passwd | grep claypool Clean up Running Initialization Terminate Dispatch I/O request Create Interrupt 3 processes cat grep bash Ready Waiting I/O complete (See process states with top)

OS as a Process Scheduler ... cat ls disk vid OS Process Scheduler Simple OS view – just schedule processes! Even OS services (e.g., file system) are just processes Small scheduler handles interrupts, stopping and starting processes (policy decides when) Ok, what are mechanisms needed to make this happen?

Program  Process int g_x main() { ... } A() { f = open() What information do we need to keep track of a process (i.e., a running program)? ?

Program  Process Low-level machinery (mechanisms) – to store program context (Discuss policies later in scheduling) Current execution location Intermediate computations (heap and stack) Access to resources (e.g., I/O and files open) int g_x main() { ... } A() { f = open() int g_x main() { ... } A() { f = open() Heap A main Stack g_x I/O f Process Control Block (PCB)

Outline Motivation (done) Control block (next) Switching Control

Process Control Block OS keeps one Process Control Block (PCB) for each process process state program counter registers memory management open devices … OS keeps list/table of PCB’s for all processes (use when scheduling) Code examples: SOS “pcb.h”: ProcessControlBlock Xv6 “proc.h”: proc Linux “sched.h”: task_struct

Process Control Block – Summary Info List of typical attributes in PCB

Outline Motivation (done) Control block (done) Switching (next)

Process Creation When are processes created?

Process Creation System initialization Created on demand by user BIOS Boot loader System initialization When OS boots, variety of system processes created init – parent of all processes (pid 1) Background, don’t need to interact with user (daemons for “guiding spirit”) Note, foreground processes get input from user Created on demand by user Shell command or, e.g., double clicking icon Execution of system call Process itself may create other processes to complete task Created by batch job Queued awaiting necessary resources. When available, create process(es) init Daemons Shell User command User command

Process Termination When are processes terminated?

Process Termination Voluntarily Involuntarily Make system call to exit() or return from main() Involuntarily By OS if “misbehave” – e.g., divide by zero, invalid memory access By another process (e.g., kill or signal())

Creation/Termination Example – Unix Shell See: “shell-v0.c” System call: fork() Creates (nearly) identical copy of process Return value different for child/parent System call: exec() Over-write with new process address space Shell Uses fork() and exec()  Simple! See: “shell-v1.c”

Model for Multiprogramming CPU switches from process to process Each runs for 10s or 100s of milliseconds Block for I/O E.g., disk read Other interrupt E.g., I/O complete “timeslice” is over (configurable parameter) scheduled Silberschatz & Galvin, 5th Ed, Wiley, Fig 4.3 Operating System Concepts

Context Switch Pure overhead So … want it to be fast, fast, fast typically 1 to 1000 microseconds Sometimes special hardware to speed up Real-time wants worst case (e.g., max 20 microseconds) When to switch contexts to another process is process scheduling

Interrupt Handling Mechanism Store PC (hardware) Load new PC (hardware) Jump to interrupt service procedure Save PCB information (assembly) Set up new stack (assembly) Set “waiting” proc to “ready” (C) Service interrupt (C and assembly) Invoke scheduler (C) Newly awakened process (context-switch) Previously running process

Outline Motivation (done) Control block (done) Switching (done) Control (next) Chapter 6 OPERATING SYSTEMS: THREE EASY PIECES  http://pages.cs.wisc.edu/~remzi/OSTEP/cpu-mechanisms.pdf

The Problem – Virtualizing CPU with Control Time Ready?! A Illegal! (e.g., read() w/out perm) Time THE CRUX OF THE PROBLEM: HOW TO EFFICIENTLY VIRTUALIZE CPU WITH CONTROL? OS must virtualize CPU efficiently while retaining control over system. Note: hardware support required!

Solution – Limited Direct Execution Still allow programs to directly run (e.g., on CPU) – i.e., no “sandbox” interpretation But limit permissions Hardware provides two (sometimes more) modes User mode – certain operations/access not allowed Kernel mode – full access allowed Allows OS to protect against Faulty processes Malicious processes Some instructions and memory locations are designated as privileged Only executable or accessible in kernel mode System calls, traps, and interrupts change mode from user to kernel Return from system call resets mode to user

Trap – Transition User to Kernel Mode Save {pc, registers, return} to stack Restore (pop) stack But … wow to know what code to execute for system call? i.e., how to know where system call is?

Trap – System Call Lookup Table syscall number syscall table Each system call has own number/identity Initialized at boot time Kernel trap handler uses syscall number to index into table of syscall routines Unique to each OS

E.g., Accessing Kernel via Library

Inside Kernel Mode, OS can … Not readable or writeable in user mode Read and modify data structures not in user address space Control devices and hardware settings forbidden to user processes Invoke operating system functions not available to user processes Access address of space of invoking process SP  PC 

Involuntary Transition User to Kernel Mode E.g., in user mode, memory violation generates interrupt Limit Register Memory yes CPU < no error Switch to kernel mode Handle error (e.g., terminate process)

The Problem – Virtualizing the CPU Time Ready?! A  ? Illegal! (e.g., read() w/out perm) Time THE CRUX OF THE PROBLEM: HOW TO EFFICIENTLY VIRTUALIZE CPU WITH CONTROL? What if process doesn’t voluntarily give up control? It doesn’t make a system call (so, can’t check) and it doesn’t make a violation. e.g., while(1) {}

Solution – Special Timer Hardware Pulse from 5 to 300 MHz Crystal Oscillator Decrement counter when == 0  generate interrupt Holding register to load counter Use to control clock ticks (i.e., length of timer) When timer interrupt occurs, OS regains control E.g., can run scheduler to pick new process

Outline Motivation (done) Control block (done) Switching (done) Control (done)