CS 3733 Operating Systems

Similar documents
IPC and Unix Special Files

CS3733: Operating Systems

CS 5523: Operating Systems

CS 3723 Operating Systems: Final Review

CS3733: Operating Systems

CHAPTER 2: PROCESS MANAGEMENT

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio

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

Lecture 2 Process Management

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

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

Chapter 3: Process Concept

Chapter 3: Process Concept

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

Chapter 3: Process Concept

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

Operating Systems Comprehensive Exam. Spring Student ID # 3/20/2013

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

CS370 Operating Systems

CS 322 Operating Systems Practice Midterm Questions

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University

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

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

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

Announcements/Reminders

Exam Guide COMPSCI 386

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

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

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

Retrieval Exercises for CS 3733 Operating Systems. Instructor: Dr. Turgay Korkmaz Department Computer Science The University of Texas at San Antonio

Course: Operating Systems Instructor: M Umair. M Umair

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

CS Operating system Fall Midterm I -- Oct 5, 2017 You have 75 min. Good Luck!

Processes. Process Concept

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

So far. Next: scheduling next process from Wait to Run. 1/31/08 CSE 30341: Operating Systems Principles

Unix File and I/O. Outline. Storing Information. File Systems. (USP Chapters 4 and 5) Instructor: Dr. Tongping Liu

Processes and Threads

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

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

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

CS Operating system Summer Midterm I -- July 11, 2017 You have 115 min (10:00am-11:55pm). Good Luck!

CISC 7310X. C05: CPU Scheduling. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/1/2018 CUNY Brooklyn College

Midterm Exam. October 20th, Thursday NSC

Processes and Threads

Process Scheduling. Copyright : University of Illinois CS 241 Staff

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005

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

TDIU25: Operating Systems II. Processes, Threads and Scheduling

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

COP 4610: Introduction to Operating Systems (Spring 2014) Chapter 3: Process. Zhi Wang Florida State University

Processes. Operating System Concepts 8 th Edition

CPU Scheduling: Part I ( 5, SGG) Operating Systems. Autumn CS4023

* What are the different states for a task in an OS?

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

UNIT:2. Process Management

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

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)

Processes and Threads

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Process Management. Outline. Process vs. Program. Address Space. How do we run a program? What are steps to create a process?

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

(MCQZ-CS604 Operating Systems)

CS370 Operating Systems Midterm Review

Unit 3 : Process Management

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

Chapter 5: CPU Scheduling

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

Chapter 3: Processes

Process. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

OPERATING SYSTEMS: Lesson 4: Process Scheduling

Inter-Process Communication

Overview of Operating Systems

Operating System Labs. Yuanbin Wu

Operating Systems Comprehensive Exam. Fall Student ID # 10/31/2013

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

Process- Concept &Process Scheduling OPERATING SYSTEMS

Indian Institute of Technology, Kharagpur

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Topics: Early systems and OS overview Skim Chapters 1-2 of SGG Read Chapter 1 of USP CS 3733 Operating Systems

Operating Systems. Figure: Process States. 1 P a g e

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

SAMPLE MIDTERM QUESTIONS

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

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

CS370 Operating Systems

MARUTHI SCHOOL OF BANKING (MSB)

CMPSCI 377: Operating Systems Exam 1: Processes, Threads, CPU Scheduling and Synchronization. October 9, 2002

UNIT - II PROCESS MANAGEMENT

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

Lecture 4: Memory Management & The Programming Interface

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Scheduling

Problem Set: Processes

CHAPTER NO - 1 : Introduction:

Mon Sep 17, 2007 Lecture 3: Process Management

Chapter 3: Processes. Operating System Concepts 8th Edition

Chapter 3: Processes. Chapter 3: Processes. Process in Memory. Process Concept. Process State. Diagram of Process State

Chapter 4: Processes. Process Concept

Transcription:

What will be covered in MidtermI? CS 3733 Operating Systems Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio Basics of C programming language Processes, program and system call Scheduling File system and IO IPC communication 1 2 Lecture 1 - Outline Von Neumann Architecture Operating System: what is it? Evolution of Computer Systems and OS Concepts Different types/variations of Systems/OS Ø Parallel/distributed/real-time/embedded OS etc. OS as a resource manager Ø How does OS provide service? interrupt/system calls OS Structures and basic components Ø Process/memory/IO device managers 3 This describes a design architecture: Before, computers have fixed uses A processing unit containing an ALU and processor registers A control unit containing an instruction register or program counter A memory to store both data and instructions (Stored-program computer) External mass storage, and input and output mechanisms. 4 1

Operating Systems: Definitions A program that acts as an intermediary between the user/programs of computer and computer hardware. From system view Ø Kernel the program running at all times (all else being application programs) Ø Control program controls the execution of user programs and operations of I/O devices Ø Resource allocator manages and allocates resources Goals of Operating system Ø Convenience: Make the computer convenient to use. Ø Efficiency: Manage system resources in an efficient manner 5 OS Interface: APIs and System Calls For application programmers Application programming interface (API) Ø The run-time support system (run-time libraries) provides a system-call interface, that intercepts function calls in the API and invokes the necessary system call within the operating system System calls provide the interface between a running program and the operating system. Ø Generally available in routines written in C and C++ Ø Certain low-level tasks may have to be written using assembly language 6 Lecture 2: Outline Programs, Processes and Threads Process creation and its components States of a process and transitions PCB: Process Control Block Process (program image) in memory Argument Arrays Making Functions Safe Storage and Linkage Classes Programs vs. Processes Program: a set instructions/functions Ø To accomplish a defined task Ø Passive entity, stored as files on disk Process: a program in execution Ø Dynamic concept: running of a program Ø Unit of work in a system Multiple processes may be from a single program Ø Run/execute the program multiple times How do we run/execute a program? 7 8 2

Process: Address Space An Example: fork( ) In UNIX A process includes Ø Program code: text segment Ø Global variables: data section Ø Temporary data (local variables, function parameters, and return address etc.): Stack Ø Dynamically allocated data (malloc): Heap Ø Program counter (PC) and registers Process execution must progress in sequential fashion (a single thread) Ideally Text pid = 25 Data Stack Process Status < > int cpid = fork( ); if (cpid = = 0) { <child code> exit(0); } <parent code> wait(cpid); File File Resources Resources UNIX kernel Text pid = 26 Data Stack Process Status cpid = 26 < > int cpid = fork( ); if (cpid = = 0) { <child code> exit(0); } <parent code> wait(cpid); cpid = 0 9 10 Linkage Classes (cont.) Variables Ø Declared outside any function and function name identifiers have external linkage by default; however, they can be given internal linkage with the key word static Ø Declared inside a function are only known inside that function and are said to have no linkage Activity void main() { if (fork() == 0) { printf( a ); } else { printf( b ); waitpid(-1, NULL, 0); } printf( c ); exit(0); } List all the possible output sequences for this program. Solution: We can t make any assumption about the execution order of the parent and child. Thus, any topological sort of b -> a and a -> c is possible: acbc abcc bacc 11 3

Lecture 03: Outline Process queues and scheduling events Different levels of schedulers Preemptive vs. non-preemptive Context switches and dispatcher Performance criteria Ø Fairness, efficiency, waiting time, response time, throughput, and turnaround time; Classical schedulers: FIFO, SFJ, PSFJ, and RR CPU Gantt chart vs. process Gantt charts Scheduler A process is migrated among various queues Operating system must select, for scheduling purposes, processes from these queues in some fashion. Ø The selection process is called as Scheduler. 13 14 Non-Preemptive vs. Preemptive Non-preemptive scheduling: voluntarily give up CPU Ø Once a process has the CPU: until it finishes or needs I/O Ø Not suitable for time-sharing Ø Only IO (case 1) and process termination (case 4) can cause scheduler action Preemptive scheduling Ø Process may be taken off CPU non-voluntarily Ø Both occasions 2 and 3 may cause scheduler action Ø 2 is a special case of 3 Ø Time-sharing systems have to be preemptive! 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 via a context switch! Context of a process represented in the PCB" Context-switch time is overhead; the system does no useful work while switching" Hardware support" Ø Multiple set of registers then just change pointers" Other performance issues/problems" Ø Cache content: locality is lost" Ø TLB content: may need to flush" 15 4

CPU-bound vs. IO-Bound Performance Criteria Bursts of CPU usage alternate with periods of I/O wait CPU-bound: high CPU utilization, interrupts are processed slowly I/O-bound: more time is spending on requesting data than processing it Process 1: CPU bound" Process 2:" I/O bound" Time" CPU bursts" Total CPU usage" I/O waits" Total CPU usage" 17 Methods to measure performance of CPU schedulers Fairness Ø Each process gets a fair share of CPU in Multiprogramming Efficiency: CPU Utilization Ø Percentage of time CPU is busy; e.g., 40%, 80%,100%(?) Throughput Ø Number of processes completed per unit time Ø E.g., 10 per second; or 1 per hour Turnaround Time Ø Time from submission to termination Ø Sum of CPU time, I/O time, and waiting time 18 Performance Criteria (cont.) Waiting time Ø Time for a process waiting for CPU in a ready queue Ø Scheduling algorithms: no effect on CPU or I/O time Response time Ø Time between submission and the first response Ø Good metric for interactive systems Classical Scheduling Algorithms First-Come First Served (FCFS) Shortest Job First (SJF) Preemptive Shortest (remaining) Job First (PSJF) Round Robin Scheduling (RR) Response time variance Ø For interactive systems, response time should NOT vary too much 19 20 5

Lecture 05: Outline Basics of File Systems Directory and Unix File System: inodes UNIX I/O System Calls: open, close, read, write, ioctl File Representations: FDT, SFT, inode table fork and inheritance, Filters and redirection File pointers and buffering Directory operations Links of Files: Hard vs. Symbolic inode: Store File Information (SGG 12.4) Traditional UNIX inode structure. 21 22 Unix I/O Related System Calls Device independence: uniform device interface I/O through device drivers with standard interface Use file descriptors 3 file descriptors open when a program starts Ø STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO 5 main system calls for I/O Ø open, close, read, write, ioctl Ø Return -1 on error and set errno 23 File Representation File Descriptor Table: user program area Ø An array of pointers indexed by the file descriptors Ø The pointers point to entries in System File Table System File Table: kernel area Ø Contains entries for each open file Ø Entries contain pointers to a table of inodes kept in memory Ø Other information in an entry: current file offset; count of file descriptors that are using this entry; Ø When a file is closed, the count is decremented. The entry is freed when the count becomes 0. In-Memory Inode Table: copies of used inodes 24 6

File Representation (cont.) Redirection A program can modify the file descriptor table entry so that it points to a different entry in the system file table. This action is known as redirection. Figure 4.2 (page 120): Relationship between the file descriptor table, the system file table and the in-memory inode table. 25 26 Filters and Redirection Example 4.35 (p129) Ø cat > my.file 27 Links in Unix Link: association between a filename and an inode Two types of links in Unix: Hard vs. Symbolic/Soft Ø Hard link: A hard link just creates another file with a link to the same underlying inode. Ø Soft link: a link to another filename in the file system When a file is created Ø A new inode is assigned Ø A new directory entry is created: directly link the filename to its inode à hard link Ø inode tracks the number of hard links to the inode Additional hard links Ø Created : ln oldname newname 28 7

Lecture 06: Outline Inter-Process communication (IPC) Pipe and its operations FIFOs: named pipes Ø Allow un-related processes to communicate Ring of communicating processes Ø Steps for Ring Creation with Pipes Ø A Ring of n Processes Other issues in token ring Ø Which process to write/read: token management Pipe: Communication Buffer Create a pipe: system call pipe() #include <unistd.h> int pipe(int fildes[2]); Ø Create a unidirectional communication buffer with two file descriptors: fildes[0] for read and fildes[1] for write Ø Data write and read on a first-in-first-out base Ø No external or permanent name, and can only be accessed through two file descriptors Ø The pipe can only be used by the process that created it and its descendants (i.e., child & grand-child processes) 29 30 Program 6.1, parentwritepipe.c, page 185 Parent/Child File Descriptor Tables Which process write? Which process read? Which process write/read first? 31 32 8

Pipes and Simple Redirection Example 6.5, page 188: ls -l sort -n +4 After both dup2 functions 33 34 After Close Unnecessary File Descriptors Problems of Pipe Pros Ø simple Ø flexible Ø efficient communication Cons: Ø no way to open an already existing pipe. This makes it impossible for two arbitrary processes to share the same pipe, unless the pipe was created by a common ancestor process. 35 36 9

Named Pipes (FIFO) Named Pipes are more powerful than ordinary pipes " Communication is bidirectional " No parent-child/sibling relationship is necessary between the communicating processes " Several processes can use the named pipe for communication " Provided on both UNIX and Windows systems" Benefits of Named Pipes Named pipes are very simple to use. mkfifo is a thread-safe function. No synchronization mechanism is needed when using named pipes. write (using write function call) to a named pipe is guaranteed to be atomic. It is atomic even if the named pipe is opened in non-blocking mode. Named pipes have permissions (read and write) associated with them, unlike anonymous pipes. An Example of Unidirectional Ring Samples A ring of 5 nodes Ø Nodes represent processes Ø Links represent a unidirectional pipe How do the processes communicate? Ø Message with target PID Ø Receive targeted message Ø Forward other messages 39 40 10

Samples [5 pts] What is the difference between a process and a program? Samples3 Similar to Assignment2 Ø Compute the CPU utilization, finishing time and waiting time 41 42 11