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

Similar documents
Creating Threads COMP755

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

Process Description and Control. Chapter 3

Process Description and Control

Process Description and Control. Chapter 3

Parallel Programming Languages COMP360

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Process Description and Control. Chapter 3

Operating System Control Structures

Major Requirements of an OS

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

IT 540 Operating Systems ECE519 Advanced Operating Systems

Process Description and Control. Major Requirements of an Operating System

Major Requirements of an Operating System Process Description and Control

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

W4118 Operating Systems. Junfeng Yang

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

Processes. Process Concept

Process. Discussion session 3 1/30/2016

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

Process. Program Vs. process. During execution, the process may be in one of the following states

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

Process Description and Control

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

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

CSC 539: Operating Systems Structure and Design. Spring 2006

Multiprogramming. Evolution of OS. Today. Comp 104: Operating Systems Concepts 28/01/2013. Processes Management Scheduling & Resource Allocation

Processes, PCB, Context Switch

Processes and Threads

Chapter 3: Process-Concept. Operating System Concepts 8 th Edition,

Operating Systems. Lecture 3- Process Description and Control. Masood Niazi Torshiz

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

3.1 Introduction. Computers perform operations concurrently

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

Lecture 4: Process Management

Computer Systems II. First Two Major Computer System Evolution Steps

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

REVIEW OF COMMONLY USED DATA STRUCTURES IN OS

Process Description and Control

Processes. Sanzheng Qiao. December, Department of Computing and Software

Chapter 3 Process Description and Control

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

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

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

Operating Systems. Computer Science & Information Technology (CS) Rank under AIR 100

Part V. Process Management. Sadeghi, Cubaleska RUB Course Operating System Security Memory Management and Protection

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

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

CSCE 313: Intro to Computer Systems

Process Creation and Control

Course: Operating Systems Instructor: M Umair. M Umair

Slide 6-1. Processes. Operating Systems: A Modern Perspective, Chapter 6. Copyright 2004 Pearson Education, Inc.

csci3411: Operating Systems

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Part II Processes and Threads Process Basics

Inter-Process Communication and Synchronization of Processes, Threads and Tasks: Lesson-1: PROCESS

Processes and Non-Preemptive Scheduling. Otto J. Anshus

PROCESS CONCEPTS. Process Concept Relationship to a Program What is a Process? Process Lifecycle Process Management Inter-Process Communication 2.

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)

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

آنستیتیوت تکنالوجی معلوماتی و مخابراتی ICTI

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

Processes. Dr. Yingwu Zhu

518 Lecture Notes Week 3

CS 31: Intro to Systems Processes. Kevin Webb Swarthmore College March 31, 2016

ENGR 3950U / CSCI 3020U Midterm Exam SOLUTIONS, Fall 2012 SOLUTIONS

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - III Processes. Louisiana State University. Virtual Machines Processes

CHAPTER 2: PROCESS MANAGEMENT

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

CS Lecture 2! Processes! George Mason University! Fall 2010!

Operating Systems Process description and control

CSCE Introduction to Computer Systems Spring 2019

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

What Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals

Chapter 3: Processes. Operating System Concepts Essentials 2 nd Edition

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Processes. CS3026 Operating Systems Lecture 05

Chapter 3: Processes

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Wednesday, September 14, Chapter 3: Processes

Mon Sep 17, 2007 Lecture 3: Process Management

CS 326: Operating Systems. Process Execution. Lecture 5

Processes. CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers University

Processes and Threads

Killing Zombies, Working, Sleeping, and Spawning Children

Process Concepts 8/21/2014. CS341: Operating System. Scheduling: Theoretical Analysis

OS Main Goals. 10/24/2013 Operating Systems, Beykent University 1

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

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

CS 3733 Operating Systems

Lecture 2 Process Management

OS Lab Tutorial 1. Spawning processes Shared memory

Introduction to Processes in Computer Systems SEEM

! The Process Control Block (PCB) " is included in the context,

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

Fall 2015 COMP Operating Systems. Lab #3

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Chap 4, 5: Process. Dongkun Shin, SKKU

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed

Transcription:

OS Structure Processes COMP755 Advanced Operating Systems An OS has many parts. The Kernel is the core of the OS. It controls the execution of the system. Many OS features run outside of the kernel, such as the shell. 1 2 OS Structure Modes of Execution Kernel Mode more privileged mode has complete control of the processor and all its instructions, registers, and memory not desirable for user programs User Mode less privileged mode user program typically execute in this mode parts of the OS run in this mode 3 4 Typical Functions of an OS Kernel Process Management Memory Management I/O Management Support Functions Non-Kernel OS Shell user interface to the OS. In Microsoft Windows, this is called the Explorer (not the Internet Explorer). File Sharing Remote Procedure Calls Utilities 5 6

The Process All multiprogramming OSs are built around the concept of processes. A process is something akin to a program. Some programs have multiple processes and the OS has several processes. A process has: memory ability to use the CPU (a thread) resources allocated to it Multiple Processes There are usually many processes existing in the system. If there is only one CPU, then only one process can be running at any one time. Other processes might be waiting to run. Some (most) processes will be blocked waiting for something to happen (i.e. I/O) 7 8 Sharing the System Most programs perform a lot of I/O and therefore spend a lot of time waiting for I/O to complete. When a program is waiting for I/O, another program can be running. Some programs wait for a very long time for input (such as input from a keyboard, mouse or network) From a programmer's point of view, the user is a peripheral that types when you issue a read request. - P. Williams 9 10 Process Creation When a process is created, the OS Builds the data structures that are used to manage the process Allocates address space in main memory to the process When does a process get created? When a program is started Created by OS to provide a service to a user (ex: printing a file) Spawned by an existing process Process Termination User quits an application (e.g. word processor) Task completes Error and fault conditions 11 12

A Five-State Process Model Queue View of Process States 13 14 Process States Running: The process is being executed Ready: The process is prepared to execute when given the opportunity Blocked: The process can not execute until some event occurs, such as the completion of an I/O operation Process States New: The OS is still creating the data structures and allocating memory for the Exit: The process is no longer eligible for execution. The OS is in the process of releasing the resources allocated to this 15 16 Process Transitions New Ready: When a process becomes ready to be executed. Ready Running: When the CPU is available, the dispatcher selects a new process to run Running Ready: The running process has run long enough for now; the running process gets interrupted because a higher priority process is in the ready state (preempted) Process Transitions (cont.) Running Blocked: When a process requests something for which it must wait (e.g., initiates I/O, wait for input from another process) Blocked Ready: When the event for which it was waiting occurs Running Exit: A process is done or has failed. 17 18

Queuing Model Multiple Blocked Queues Dispatcher A part of the OS that gives the processor from one process to another Selects a process from the queue to execute after interrupt or process termination Prevents a single process from monopolizing the processor time 19 20 Context Switch When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process Context-switch time is overhead; the system does no useful work while switching Time dependent on hardware support Operating System Control Structures An OS maintains several tables for managing processes and resources: Memory tables I/O tables File tables Process tables 21 22 Process Control Structures Process image: the collection of program, data and attributes (process control block) Process control block: the collection of attributes of the process that are used by OS for process control Process Control Block (PCB) Process Identification Information Processor Identifier (PID) 16 bit integer unique for each process PID of the parent process User identifier who is responsible for the job 23 24

PCB Contents CPU State Information What the CPU needs to run this User-visible registers Program Counter PSW Stack pointers PCB Contents Scheduling and state information Process state priority event for which the process is waiting (if blocked) Process relationships may hold pointers to other PCBs for process queues, parent-child relationships and other structures 25 26 PCB Contents Inter-process communication (IPC) may hold flags and signals for IPC Process privileges Memory management pointers to segment/page tables assigned to this process Resource ownership and utilization resources in use: opened files, I/O devices Process Creation Assign a unique Processor ID (PID). Allocate RAM for the PCB Initialize the PCB Allocate RAM for the program (code, data, stack and heap) Copy the program into the RAM Put the PCB on the list of PCBs 27 28 Creating a new Process In C or C++, you can create a new process with the fork function int fork(); When fork is called, the RAM of the program is copied to another location is RAM. A new process is created to run in the new program address space. The new process is put on the ready list. fork function The return value of the fork function is: -11 = Error 0 = This is the process that was just created. number = This process is the parent that just executed the fork function. The number returned is the PID of the child 29 30

Fork Action Fork Action Parent Program parent Parent Program Child Program child PCB p = fork(); PCB p = fork(); p = fork(); PCB code code code data data data p = 567 p = 567 p = 0 x = 3 x = 3 x = 3 y = 5 y = 5 y = 5 stack stack stack heap 31 heap heap 32 /* Example fork program */ int counter = 0; /* loop counter */ int pid; ; /* processor ID of child */ int waitinc; ; /* wait time in seconds */ char id; /* display identifier */ pid = fork(); if (pid( < 0) { cout << "Fork error"; exit(8); } else if (pid( == 0) { // if this is the child process id = 'C'; waitinc = 1; } else { // this is the parent process id = 'P'; waitinc = 2; } for (i = 0; i < 8; i++) { counter++; cout << id << " " << counter << endl; sleep(waitinc); } cout << "end of " << id << endl; } 33 Sharing Memory Creating a new process makes a completely new address space with a copy of the original program. None of the variables in the parent copy are accessible by the child Programmers can make a shared memory segment to communicate. 34 shmget The shmget function creates a shared memory segment. int shmget(int key, int size, int flags); key is the id of the existing shared memory segment or IPC_PRIVATE. size is the size of the segment to make. flags should be IPC_CREAT+0666 returns the shared memory id 35 shmat The shmat (shared memory attach) function gets the address of a shared memory segment. shmat( shared_id, 0, 0); shared_id is the return value from shmget. returns the address of the shared memory segment. 36

shmctl Shared memory control function can be used to delete a shared memory segment. shmctl(shared_id, IPC_RMID, NULL); shared_id is the return value from shmget. IPC_RMID is the function code to delete a shared segment. Programming Note Shared memory segments are permanent data structures. They do NOT go away when the program terminates. Be sure to delete any and all shared memory segments you create. 37 38 Multiple Process Conflicts A process or thread can be halted at any time by the OS to run another process or thread. X++ in Machine Language LOAD R1,X ADD R1,1 OS switches to another process LOAD R1,X ADD R1,1 STORE R1,X OS switches to another process STORE R1,X 39 40