System Call. Preview. System Call. System Call. System Call 9/7/2018

Similar documents
2 Processes. 2 Processes. 2 Processes. 2.1 The Process Model. 2.1 The Process Model PROCESSES OPERATING SYSTEMS

Preview. The Thread Model Motivation of Threads Benefits of Threads Implementation of Thread

Processes The Process Model. Chapter 2. Processes and Threads. Process Termination. Process Creation

Major Requirements of an OS

CS510 Operating System Foundations. Jonathan Walpole

Announcement. Exercise #2 will be out today. Due date is next Monday

Processes The Process Model. Chapter 2 Processes and Threads. Process Termination. Process States (1) Process Hierarchies

Processes and Threads

Unit 2 : Computer and Operating System Structure

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

o Reality The CPU switches between each process rapidly (multiprogramming) Only one program is active at a given time

W4118 Operating Systems. Junfeng Yang

Chapter 2 Processes and Threads

Process Description and Control. Chapter 3

Process Description and Control

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

CSE325 Principles of Operating Systems. Processes. David P. Duggan February 1, 2011

Process. Discussion session 3 1/30/2016

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

Process Description and Control. Chapter 3

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering)

Learning Outcomes. Processes and Threads. Major Requirements of an Operating System. Processes and Threads

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Mon Sep 17, 2007 Lecture 3: Process Management

Chapter 3 Processes. Process Concept. Process Concept. Process Concept (Cont.) Process Concept (Cont.) Process Concept (Cont.)

Lecture Topics. Announcements. Today: Operating System Overview (Stallings, chapter , ) Next: Processes (Stallings, chapter

CSC 539: Operating Systems Structure and Design. Spring 2006

IT 540 Operating Systems ECE519 Advanced Operating Systems

EECS 3221 Operating System Fundamentals

EECS 3221 Operating System Fundamentals

Processes and Non-Preemptive Scheduling. Otto J. Anshus

CISC 7310X. C03: Process. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 2/15/2018 CUNY Brooklyn College

Process Time. Steven M. Bellovin January 25,

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems, 3rd edition. Uses content with permission from Assoc. Prof. Florin Fortis, PhD

Processes and Threads

Process Description and Control

Computer System Overview

Operating Systems Overview. Chapter 2

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

Eastern Mediterranean University School of Computing and Technology Department of Information Technology. ITEC202 Operating Systems

CS 326: Operating Systems. Process Execution. Lecture 5

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

Motivation of Threads. Preview. Motivation of Threads. Motivation of Threads. Motivation of Threads. Motivation of Threads 9/12/2018.

1 PROCESSES PROCESS CONCEPT The Process Process State Process Control Block 5

Processes. OS Structure. OS Structure. Modes of Execution. Typical Functions of an OS Kernel. Non-Kernel OS. COMP755 Advanced Operating Systems

Operating Systems, Fall

Processes. CS3026 Operating Systems Lecture 05

Master level: Operating systems, distributed systems, networking,

Process Description and Control. Major Requirements of an Operating System

Major Requirements of an Operating System Process Description and Control

ESE 333 Real-Time Operating Systems 2 What is an operating system? Two views: 1. Top-down view: Extended machine ffl Covers the details of the hardwar

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

Process Description and Control. Chapter 3

Processes. CSE 2431: Introduction to Operating Systems Reading: Chap. 3, [OSC]

What is an Operating System? A Whirlwind Tour of Operating Systems. How did OS evolve? How did OS evolve?

Operating Systems Structure and Processes Lars Ailo Bongo Spring 2017 (using slides by Otto J. Anshus University of Tromsø/Oslo)

Four Components of a Computer System

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

Jan 20, 2005 Lecture 2: Multiprogramming OS

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 3 Process Description and Control

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

Chapter 3: Processes. Operating System Concepts 8 th Edition,

The Challenges of X86 Hardware Virtualization. GCC- Virtualization: Rajeev Wankar 36

Operating System. Operating System Overview. Structure of a Computer System. Structure of a Computer System. Structure of a Computer System

Last class: OS and Architecture. OS and Computer Architecture

Last class: OS and Architecture. Chapter 3: Operating-System Structures. OS and Computer Architecture. Common System Components

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar

Process Description and Control

1 System & Activities

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

OS and Computer Architecture. Chapter 3: Operating-System Structures. Common System Components. Process Management

Computer Systems II. First Two Major Computer System Evolution Steps

Chapter 3 Process Description and Control

Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

Q1. State True/false with jusification if the answer is false:

Lecture 4: Threads; weaving control flow

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

B. V. Patel Institute of Business Management, Computer &Information Technology, UTU

Course: Operating Systems Instructor: M Umair. M Umair

Processes COMPSCI 386

CS399 New Beginnings. Jonathan Walpole

Operating Systems CS 571

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

CSE 380 Computer Operating Systems. Instructor: Insup Lee. University of Pennsylvania Fall 2003

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

COMP 3100 Operating Systems

Processes and Threads

Operating Systems. Operating System Structure. Lecture 2 Michael O Boyle

PROCESSES & THREADS. Charles Abzug, Ph.D. Department of Computer Science James Madison University Harrisonburg, VA Charles Abzug

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

CSCE Introduction to Computer Systems Spring 2019

CS 333 Introduction to Operating Systems. Class 2 OS-Related Hardware & Software The Process Concept

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

Killing Zombies, Working, Sleeping, and Spawning Children

Transcription:

Preview Operating System Structure Monolithic Layered System Microkernel Virtual Machine Process Management Process Models Process Creation Process Termination Process State Process Implementation Operating System s two main functions Providing abstractions (interface) to user program (usually I/O services) Managing resources. If a process is running a user program (in user s mode) and need a system service such as reading data from a file, it must execute a trap instruction to transfer control from a user s process to kernel. OS check request and carries out the system call and returns control to the user 1 2 #include <unistd.h> ssize_t read(int fd, const void *buffer, size_t nbyte); Return number of byte read for ok, -1 for error The read() system call attempts to read nbyte bytes to the buffer pointed to by buffer from the file associated with the open file descriptor, fd. It returns the number of bytes actually read. 3 4 System call handler table: Save each handler s location Step 1 ~ 3: push parameters onto the stack Step 4: actual function call Step 5: patch read instruction to IR in CPU Step 6: (trap) change mode to kernel Step 7: dispatch system call service (or hander) number (read), Step 8: run system call service routine (or handler) Step 9, 10: change mode to user result might be saved in a register Step 11: clear stack by increment stack pointer 5 6 1

Operating System Structures Monolithic Layered System Microkernels Virtual machine Client- module Exokernels (Monolithic System) It is written as a collection of procedures, each of which can call any of the other ones whenever it needs to. Each procedure in the system has a welldefined interface in terms of parameters and results, and each one is free to call any other one, if the latter provides some useful computation that the former needs. It is possible to have some structure for a monolithic system 7 8 (Monolithic System) (Monolithic System) Possible structure for a monolithic system A main program invoke service functions Service functions carry out the system calls Utility functions helps service functions 9 10 (Layered System) (Microkernels) Operating system is divided into several layers and each layer works for different rule. Layer 0 process management Layer 1 memory management Layer 2 inter-process communication Layer 3 Input /Output management Layer 4 user program Layer 5 system operator process With the layered approach, the designers have a choice where to draw the kernel-user boundary. Traditionally, all the layers went in the kernel, but it is not necessary since one bug in kernel might cause entire system down. Various researchers studied the number of bugs (logical) per 1000 lines of code. About 5 million lines of codes for layered kernel likely to contains 10000 to 50000 kernel bugs. Not all of bugs are fatal. 11 12 2

applications 9/7/2018 (Microkernels) (Microkernels) The basic idea of the microkernel is to achieve high reliability by splitting the operating system up into small welldefined module. Only one of module (microkernel) run in kernel mode and the rest run as users mode. Ex) A bug in the audio driver will cause the sound to be garbled or stop, but not crash the computer. OS Application Software System call Handlers File System Device Drivers Scheduler Memory Manager.. Hardware Layered OS Run in user s mode Run in kernel s mode Application Software File System I/O Device Display Devices.... Microkernel Memory management Process management Deadlock management Hardware Microkernel OS Device Drivers OS 13 14 Virtual machine monitor(hypervisor) runs on the bare hardware and does multiprogramming, by providing several virtual machines. Each virtual machines are exact copies of the bare hardware, including kernel/user mode, I/O and everything else the real machine has. Different virtual machine can run different operating system. Example of virtualization Many companies have traditionally run their mail servers, Web servers, FTP servers and other servers on separate computer with different operating system. Several server can run on the same machine without having a crash of one server bring down the rest since each server running on different virtual machine. 15 16 Mail Virtual Machines Web VM 1 VM 2 VM n FTP Mail Web FTP Operating System A Bare Hardware Other VM 1 VM 2 VM 3 VM 4 VM n OS OS OS OS OS Hypervisor Physical Hardware OS OS OS Hypervisor Application software Host Operating System Physical Hardware Other Type 1 (bare metal hypervisor) Type 2 (Hosted hypervisor) 17 18 3

The Processes Chapter 2 Process & Thread We assume that there is only one CPU (processor) in our system. Multiprogramming several jobs are loaded in a memory, operating system simulate Pseudo parallelism (virtual). OS schedule the CPU times for processes by switches from one process to another based on the scheduling algorithm and process state (by short-term scheduler). 19 20 The Processes The Process Model CPU Registers ALU Control Unit RAM Job1 Job2 Job3 OS 21 We can consider processes as two different point of view. Real Model Multiprogramming Conceptual (virtual) Model each process has its own virtual CPU, PC, registers, stack pointer Check the following concept Virtual machine-each OS run on its own machine Virtual memory each process has its own Memory Virtual process model each process run on it s own machine 22 The Process Model The Process Model With the CPU switching back and forth among the processes, a process can hold CPU during its time term. The time term which assigned to each processes might not be uniform. The time term for a process might need be calculated based on the types of jobs I/O bounded, CPU bounded or priority (usually CPU bounded job need more CPU time then I/O bounded job). 23 24 4

Process Creation Process Creation System initialization - When an OS is booted, several processes are created. A running process create a process by system call running process request a system call to create one or more new processes web server example A system user create by executing a program in interactive system, users can start a program by typing a command or click icon Initiation of a batch job mainframe computer Process Creation UNIX system call fork create a new process In Window system call CreateProcess create a new process Once a child process is created, both parent and child have their own distinct address two process might need interprocess communication (for sharing resources) 25 26 Process Termination A process terminate due to one of the following condition Normal exit a process finish their job (voluntary) Error exit the process discovers a fatal error compiler try to compile a program, there is no such a file (voluntary). Fatal error error caused by the process a process try to modify the memory location where other process is located (involuntary) Killed by another process a deadlock is occurred. OS terminate a process at a time to resolve the deadlock (involuntary) 27 Process State 1 Block Running 4 3 Ready 1. Process blocks for input 2. Short-Term Scheduler picks a process 3. A process time out its time term 4. Input becomes available 2 28 Process Implementation To implement the process, operating system maintain each process s information in its process table (or process control block (PCB)) When a running process s state changes from running to block state or ready state, OS need to save information for the process. Shot term scheduler (CPU scheduler) select a process from the ready queue. OS need to restore information for the selected process from its process table into CPU Process Implementation Contents of a Process Table (or PCB) Process status The state may be new ready, running, blocked Program counter Address of next instructions for the process CPU registers registers vary in number and type, depending on the computer architecture. (Accumulators, index registers, stack pointers, general-purpose registers, plus any condition code information CPU scheduling information a process priority, pointers to the scheduling queues. Memory management information the base and limit registers, the page tables, the segmentation tables Accounting information the amount of CPU and real time used, time limits, account numbers, process numbers, I/O status information list of I/O devices allocated to the process, list of open files, and so on 29 30 5

In a traditional OS, each process has an address space and a single thread of control. In many modern software, multiple activities are running on at once. Each of them are doing the different job. By decomposing an application into multiple sequential threads that runs in quasi-parallel Each threads inside a process need its independent spaces (similar to process table) for running but sharing the same address space of program. Thread might be controlled by OS or runtime system. Each threads are running in the same memory space, but each threads are usually running in the different part of program. When a thread is created, system need create thread table for saving thread s runtime information. System need keep each threads information in thread table. 31 32 Between processes, when a state of a running process changes, system need interrupt for context switches. By decomposing an application into multiple sequential threads, each threads run different part of an process independently without interrupts, context switches. 33 Threads Threads are mini-processes in a process!!! multiple execution in the same process environment. It is made up with a thread ID, a program counter, a register set, and a stack. Different threads are not quite as independent as different processes since they share same address space It shares with other threads belonging to the same process its code section, data section and other operating system resources such as files and signals. 34 Multiprogramming vs. multi thread Multiple process running on a computer Process are share CPU, physical memory and I/O devices Multiple threads running on a process the threads are share resources of a process (address space, open files, and other recourses) With thread the ability for multiple threads of execution to share a set of resources so they can work together closely to perform same task. Each threads working on a program runs a different part of program Process 1 Process 2 Process 3 Process User space thread thread Kernel kernel kernel space a) A process with one thread a) A process with multiple thread 35 36 6

The CPU switches rapidly back and forth among the threads in the single CPU system (Same idea as multiprogramming) No protection between threads using same address space (share the global variables) A thread can be in any one of several states: running, blocked, ready 37 38 Since each thread usually call different functions from the same address space (each thread executing different part of program), each thread need its own stack. A multithread software start with single thread. The thread has ability to create new threads by calling a library procedure (i.e. thread_create) When a thread has finish its work, it can exit by calling a library procedure ( i.e. thread_exit) pthread functions for POSIX 39 40 41 7