OS Structure, Processes & Process Management

Similar documents
Computer Systems II. Unix system calls. fork( ) wait( ) exit( ) How To Create New Processes? Creating and Executing Processes

CS161: Operating Systems

Example of Standard API

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Operating System Components

ELEC 377. Operating Systems. Week 1 Class 3

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Introduction. What is an Operating System?

Chapter 3 Operating-System Structures

Chapter 2 System Structures

Operating System Structures

CSE 120 Principles of Operating Systems. Modules, Interfaces, Structure

OPERATING SYSTEM SERVICES

Operating System Organization. Purpose of an OS

Real Time Programming: Concepts

Chapter 3: Operating-System Structures. System Components Operating System Services System Calls System Programs System Structure Virtual Machines

Chapter 6, The Operating System Machine Level

Chapter 3: Operating-System Structures. Common System Components

Chapter 2: OS Overview

Process Description and Control william stallings, maurizio pizzonia - sistemi operativi

Introduction to Operating Systems. Perspective of the Computer. System Software. Indiana University Chen Yu

CS420: Operating Systems OS Services & System Calls

Components of a Computer System

Operating System Components and Services

How To Understand How A Process Works In Unix (Shell) (Shell Shell) (Program) (Unix) (For A Non-Program) And (Shell).Orgode) (Powerpoint) (Permanent) (Processes

An Implementation Of Multiprocessor Linux

Lecture 5. User-Mode Linux. Jeff Dike. November 7, Operating Systems Practical. OSP Lecture 5, UML 1/33

Multiprogramming. IT 3123 Hardware and Software Concepts. Program Dispatching. Multiprogramming. Program Dispatching. Program Dispatching

CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17

CSC 2405: Computer Systems II

Linux Kernel Architecture

Kernel Types System Calls. Operating Systems. Autumn 2013 CS4023

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

Process definition Concurrency Process status Process attributes PROCESES 1.3

CHAPTER 15: Operating Systems: An Overview

CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson

Operating System Structures

Operating System Structure

Page 1 of 5. IS 335: Information Technology in Business Lecture Outline Operating Systems

A Look through the Android Stack

Operating System Overview. Otto J. Anshus

How To Write A Windows Operating System (Windows) (For Linux) (Windows 2) (Programming) (Operating System) (Permanent) (Powerbook) (Unix) (Amd64) (Win2) (X

Libmonitor: A Tool for First-Party Monitoring

Operating Systems 4 th Class

COS 318: Operating Systems

Thomas Fahrig Senior Developer Hypervisor Team. Hypervisor Architecture Terminology Goals Basics Details

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

CS414 SP 2007 Assignment 1

Operating Systems: Basic Concepts and History

System Calls and Standard I/O

Chapter 3. Operating Systems

OS Concepts and structure

The System Monitor Handbook. Chris Schlaeger John Tapsell Chris Schlaeger Tobias Koenig

Lesson Objectives. To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

OPERATING SYSTEMS STRUCTURES

CPS221 Lecture: Operating System Structure; Virtual Machines

How to design and implement firmware for embedded systems

Operating Systems Concepts: Chapter 7: Scheduling Strategies

Microkernels, virtualization, exokernels. Tutorial 1 CSC469

I/O Device and Drivers

CS10110 Introduction to personal computer equipment

The Linux Kernel: Process Management. CS591 (Spring 2001)

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Operating Systems. 05. Threads. Paul Krzyzanowski. Rutgers University. Spring 2015

SYSTEM ecos Embedded Configurable Operating System

LSN 10 Linux Overview

This tutorial will take you through step by step approach while learning Operating System concepts.

x86 ISA Modifications to support Virtual Machines

Overview of Operating Systems Instructor: Dr. Tongping Liu

Operating System Tutorial

Lecture 25 Symbian OS

How do Users and Processes interact with the Operating System? Services for Processes. OS Structure with Services. Services for the OS Itself

Operating Systems for Parallel Processing Assistent Lecturer Alecu Felician Economic Informatics Department Academy of Economic Studies Bucharest

Linux Driver Devices. Why, When, Which, How?

System Structures. Services Interface Structure

REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-12: Real Time Linux

Virtual Private Systems for FreeBSD

Kernel comparison of OpenSolaris, Windows Vista and. Linux 2.6

CHAPTER 1: OPERATING SYSTEM FUNDAMENTALS

The PC Boot Process - Windows XP.

ò Paper reading assigned for next Thursday ò Lab 2 due next Friday ò What is cooperative multitasking? ò What is preemptive multitasking?

Device Driver Best Practices in Windows Embedded Compact 7. Douglas Boling Boling Consulting Inc.

OS Thread Monitoring for DB2 Server

Outline. Review. Inter process communication Signals Fork Pipes FIFO. Spotlights

windows maurizio pizzonia roma tre university

FRONT FLYLEAF PAGE. This page has been intentionally left blank

Operating Systems. Lecture 03. February 11, 2013

Technical Properties. Mobile Operating Systems. Overview Concepts of Mobile. Functions Processes. Lecture 11. Memory Management.

Introduction to Embedded Systems. Software Update Problem

Operating system Dr. Shroouq J.

Jorix kernel: real-time scheduling

Java Troubleshooting and Performance

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

FAME Operating Systems

Computer-System Architecture

Glossary of Object Oriented Terms

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edition

Linux Syslog Messages in IBM Director

Transcription:

1 Recap OS Structure, Processes & Process Management OS functions Coordinator v Protection v Communication v Resource management Service provider v File system, device handler, Questions: How can the OS perform these functions? How is an OS invoked? What is the structure of the OS? 2 An Operating System in Action O.S. in Action (Cont d) CPU loads boot program from ROM (e.g. BIOS in PC s) After basic processes have started, the OS runs user programs, if available, otherwise enters the idle loop Boot program: Examines/checks machine configuration (number of CPU s, how much memory, number & type of hardware devices, etc.) Builds a configuration structure describing the hardware Loads the operating system, and gives it the configuration structure Operating system initialization: Initialize kernel data structures Initialize the state of all hardware devices Creates a number of processes to start operation (e.g. getty in UNIX, the Windowing system in NT, e.g.) 3 In the idle loop: OS executes an infinite loop (UNIX) OS performs some system management & profiling OS halts the processor and enter in low-power mode (notebooks) OS wakes up on: Interrupts from hardware devices Exceptions from user programs System calls from user programs Two modes of execution User mode: Restricted execution mode (applications) Supervisor mode: Unrestricted access to everything (OS) 4

5 Control Flow in an OS On Interrupts main() Idle Loop From boot Initialization RTI Return to to user user mode mode Interrupt Operating System Modules Supervisor Mode Mode System call Exception Hardware calls the operating system at a pre-specified location Operating system saves state of the user program Operating system identifies the device and cause of interrupt Responds to the interrupt Operating system restores state of the user program (if applicable) or some other user program Execute an RTI instruction to return to the user program User program continues exactly at the same point it was interrupted. Key Fact: None of this is visible to the user program 6 On Exceptions On System Calls Hardware calls the operating system at a pre-specified location Operating system identifies the cause of the exception (e.g. divide by 0) If user program has exception handling specified, then OS adjust the user program state so that it calls its handler Execute an RTI instruction to return to the user program If user program did not have a specified handler, then OS kills it and runs some other user program, as available Key Fact: Effects of exceptions are visible to user programs and cause abnormal execution flow User program executes a trap instruction (system call) Hardware calls the operating system at a pre-specified location Operating system identifies the required service and parameters (e.g. open(filename, O_RDONLY)) Operating system executes the required service Operating system sets a register to contain the result of call Execute an RTI instruction to return to the user program User program receives the result and continues Key Fact: To the user program, it appears as a function call executed under program control 7 8

9 Operating System Today High-level software architecture Operating System Structures Command Interpreter Window System User Applications Operating System (process/device/memory management, file file systems, interprocess communication, ) ) Instruction Execution & Interrupt Processing I/O Devices Middleware Memory Monolithic OS (e.g., Unix) Command Interpreter File System Security Network Support Memory Management CPU Scheduling Process Management Device Management Hardware Micro-kernel OS (e.g., Mach, Exokernel, ) Network Support Memory Mgmt. API API File Server Scheduling CPU Device Interrupt Drivers Handler Message Passing Hardware Window Server...... Boot and Init. 10 Summary Processes and Process Management What is a Program? How to run a Program? An OS is just a program: It has a main() function, which gets called only once (during boot) Like any program, it consumes resources (such as memory), can do silly things (like generating an exception), etc. But it is a very strange program: It is entered from different locations in response to external events It does not have a single thread of control, it can be invoked simultaneously by two different events (e.g. system call & an interrupt) It is not supposed to terminate It can execute any instruction in the machine 11 A program consists of code and data On running a program, the loader: reads and interprets the executable file sets up the process s memory to contain the code & data from executable pushes argc, argv on the stack sets the CPU registers properly & calls start() Program starts running at _start() _start(args) { ret = main(args); exit(ret) we say process is now running, and no longer think of program When main() returns, OS calls exit() which destroys the process and returns all resources 12

13 So, What is a Process? Anatomy of a Process A process is an abstraction that supports running programs Header mapped segments DLL s A process is the basic unit of execution in an operating system Initialized data Process s address space Stack Different processes may run several instances of the same program At a minimum, process execution requires following resources: Memory to contain the program code and data A set of CPU registers to support execution Executable File Process Control Block PC PC Stack Stack Pointer Pointer Registers Registers PID PID UID UID Priority Priority List List of of open open files files Heap Initialized data 14 Process Life Cycle Process Contexts Example: Multiprogramming Processes are always either executing, waiting to execute or waiting for an event to occur Start Ready Waiting Done Running User Program n... User Program 2 User Program 1 System Software Operating System Memory Program 1 OS Program 2 k: read() k+1: main{ save state read{ startio() schedule() endio{ schedule() main{ restore state save state I/O Device interrupt 15 16

17 Process Manipulation Process Manipulation in Unix Basic process manipulation: creation, program loading, exiting, Example: Unix Operating system Creation and deletion: fork(), exec(), wait(), exit() Process signaling: kill() Process control: ptrace(), nice(), sleep() The system creates the first process (sysproc in Unix) The first process creates other processes such that: the creator is called the parent process the created is called the child process the parent/child relationships can be expressed by a process tree In Unix, the second process is called init it creates all the gettys (login processes) and daemons it should never die it controls the system configuration (num of processes, priorities) Unix system interface includes a call to create processes fork() 18 Unix s fork() Unix s fork(): Example Usage Creates a child process such that it inherits: identical copy of all parent s variables & memory identical copy of all parent s CPU registers (except one) The execution context for the child process is a copy of the parent s context at the time of the call Both parent and child execute at the same point after fork() returns: for the child, fork() returns 0 for the parent, fork() returns the process identifier of the child Simple implementation of fork(): allocate memory for the child process copy parent s memory and CPU registers to child s Expensive!! Can Can one one reduce this this overhead without changing semantics? 19 main { int childpid; S 1 ; childpid = fork(); if(childpid == 0) <code for child process> else { <code for parent process> wait(); S 2 ; Data Stack Parent fork() childpid = 0 childpid = xxx xxx Data Stack Child 20

21 Program Loading: exec() General Purpose Process Creation The exec() call allows a process to load a different program and start execution at _start It allows a process to specify the number of arguments (argc) and the string argument array (argv) If the call is successful it is the same process but it runs a different program!! Two implementation options: overwrite current memory segments with the new values allocate new memory segments, load them with the new values, and deallocate old segments In the parent process: main() int pid = fork(); // create a child if(pid == 0) { // child continues here exec( program, argc, argv0, argv1, ); else { // parent continues here 22 Properties of the fork/exec sequence Orderly Termination: exit() In 99% of the time, we call exec() after calling fork() the memory copying during fork() operation is useless the child process will likely close the open files & connections overhead is therefore high might as well combine them in one call (OS/2) vfork() a system call that creates a process without creating an identical memory image sometimes called lightweight fork() child process is understood to call exec() almost immediately After the program finishes execution, it calls exit() This system call: takes the result of the program as an argument closes all open files, connections, etc. deallocates memory deallocates most of the OS structures supporting the process checks if parent is alive: v If so, it holds the result value until parent requests it; in this case, process does not really die, but it enters the zombie/defunct state v If not, it deallocates all data structures, the process is dead cleans up all waiting zombies 23 24

25 The wait() System Call Process Control A child program returns a value to the parent, so the parent must arrange to receive that value The wait() system call serves this purpose it puts the parent to sleep waiting for a child s result when a child calls exit(), the OS unblocks the parent and returns the value passed by exit() as a result of the wait call (along with the pid of the child) if there are no children alive, wait() returns immediately also, if there are zombies waiting for their parents, wait() returns one of the values immediately (and deallocates the zombie) OS must include calls to enable special control of a process: Priority manipulation: nice(), which specifies base process priority (initial priority) In UNIX, process priority decays as the process consumes CPU Debugging support: ptrace(), allows a process to be put under control of another process The other process can set breakpoints, examine registers, etc. Alarms and time: Sleep puts a process on a timer queue waiting for some number of seconds, supporting an alarm functionality 26 Tying it All Together: The Unix Shell while(! EOF) { read input handle regular expressions int pid = fork(); if(pid == 0) { else { exec( program, argc, argv0, argv1, ); // create a child // child continues here // parent continues here Translates <CTRL-C> to the kill() system call with SIGKILL Translates <CTRL-Z> to the kill() system call with SIGSTOP Allows input-output redirections, pipes, and a lot of other stuff that we will see later 27