1. Trang chủ
  2. » Công Nghệ Thông Tin

Lecture Operating systems: A concept-based approach (2/e): Chapter 3 - Dhananjay M. Dhamdhere

61 63 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 61
Dung lượng 1,13 MB

Nội dung

Chapter 3 - Processes and threads. This chapter begins by discussing how an application creates processes through system calls and how the presence of many processes achieves concurrency and parallelism within the application. It then describes how the operating system manages a process - how it uses the notion of process state to keep track of what a process is doing and how it reflects the effect of an event on states of affected processes. The chapter also introduces the notion of threads, describes their benefits, and illustrates their features.

PROPRIETARY MATERIAL. ©  2007 The McGraw­Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide  may be displayed, reproduced or distributed  in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw­Hill  for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission.  Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 1 Copyright © 2008 What is a process? • A process is an execution of a program (Note the emphasis on ‘an’) – A programmer uses the notion of a process to achieve concurrency within an application program * Such a program can complete earlier than a sequential program – An OS uses the notion of a process to control execution of a program * This way, the OS can handle execution of sequential and concurrent programs in a uniform manner Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  SlideNo:2 Copyrightâ2008 Example of processes in an application Consider a satellite data logging application – Specification * The satellite sends samples to earth periodically * The computer receives them in a special register * The application periodically copies a sample into a file on disk * This is a real time application — a sample has to be copied before the next sample arrives – Four processes are created for the application (see next slide) * The OS creates the primary process * This process creates three processes as its child processes by making system calls Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 3 Copyright © 2008 Tasks in a real time application for data logging • Process copies the sample into a buffer in memory • Process copies the sample from the buffer into the file • Process performs housekeeping and statistical analysis Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 4 Copyright © 2008 Process tree for the real time application • The OS creates the primary process when the application is initiated; it is called ‘main’ in this diagram • The primary process creates the other three processes through system calls; they are its child processes Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 5 Copyright © 2008 Benefits of child processes • Use of child processes has three benefits – Computation speed-up * OS may interleave operation of CPU-bound and I/O-bound child processes of an application; it speeds up operation of the application – Priority for critical functions * A child process could be created to perform a critical function It can be assigned a high priority to satisfy its time constraints – Protecting a parent process from errors * The kernel terminates a child process if an error occurs during its operation; however, the parent process is not affected * Beneficial to execute non-trusted code as a child process Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 6 Copyright © 2008 Concurrency and Parallelism • Child processes of a process may be able to operate independent of one another Q: Is this concurrency or parallelism? Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 7 Copyright © 2008 Concurrency and Parallelism • Child processes of a process may be able to operate independent of one another Is this concurrency or parallelism? – Parallelism: Operation at the same time Parallelism is not possible unless * The computer has many CPUs * The processes are truly independent of one another, so that they can be scheduled simultaneously – Concurrency: Operation in a manner that gives the impression of parallelism, but actually only one process can operate at any time Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  SlideNo:8 Copyrightâ2008 Process interaction Processes of an application may interact among themselves in four different ways – Data sharing * Data updates must be coordinated to ensure consistency – Message passing * Used for exchanging information – Synchronization * Used to ensure that processes perform their actions in a desired order – Signals * A signal conveys occurrence of an exceptional situation Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 9 Copyright © 2008 OS view of a process • The OS uses the notion of processes to organize execution of programs – The OS views a process as * An entity to which resources are allocated * A unit of work to be performed – The OS performs scheduling to organize operation of processes Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 10 Copyright © 2008 Race condition in the airline reservation system • Race conditions in the airline reservation system may have two consequences: – nextseatno may not be updated properly – Same seat number may be allocated to two passengers Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 47 Copyright © 2008 Race conditions in the airline reservations system Three possible executions are shown Q: Which of them has a race condition? Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 48 Copyright © 2008 Control synchronization between processes (a) Initiation of Pj should be delayed until Pi performs si (b) After performing Sj-1, Pj should be delayed until Pi performs si Chapter3: ProcessesandThreads Dhamdhere:OperatingSystems AConceptưBasedApproach,2ed SlideNo:49 Copyrightâ2008 Interprocess messages In the send command, process Pi specifies the message to be sent to Pj • In the receive command, process Pj specifies the memory area where it wishes to receive a message Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 50 Copyright © 2008 Benefits of message passing • Message passing has several benefits – – – – Data sharing is not necessary Processes may belong to different applications Messages cannot be tampered with by a process Kernel guarantees correctness * A message is delivered to the correct processes * A process is blocked when it wishes to receive a message and no undelivered messages exist for it Chapter3: ProcessesandThreads Dhamdhere:OperatingSystems AConceptưBasedApproach,2ed SlideNo:51 Copyrightâ2008 Signals A process can send signals to other processes to convey exceptional situations – A process must anticipate signals from other processes and must provide a signal handler for each signal * It makes a system call to specify a signal handler – The kernel activates the signal handler when a signal is sent to the process – Schematic of signals on the next slide * It uses signal vectors that are analogous to interrupt vectors  Addresses of signal handlers are entered in the signal vector  The correct signal handler is invoked when a signal is sent Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 52 Copyright © 2008 Signal handling Firm arrow : Pointers in data structures Dashed arrows: Execution time actions (a) Actions when process Pi makes an init_sig call to install a signal handler (b) Actions when signal sig1 is sent while Pi is executing instruction b1 Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 53 Copyrightâ2008 Processes in Unix A process operates in two modes—user mode and kernel mode – When a process makes a system call, it enters the kernel mode and itself executes the kernel code for handling the system call – It reenters the user mode after handling the system call – Accordingly, there are two running states: User running and kernel running * A process in the kernel running state is non-interruptible * It gets blocked when it makes an I/O request; another process is now scheduled and may make a system call  Kernel code is written in a reentrant manner, so a process can enter kernel mode even if other processes are blocked in that mode Chapter 3: Processes and Threads Dhamdhere:OperatingSystems AConceptưBasedApproach,2ed SlideNo:54 Copyrightâ2008 Process state transitions in Unix I/O request: User running → Kernel running → Blocked • End of time slice: User running → Kernel running → Ready Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 55 Copyright © 2008 Threads in Solaris • Provides three entities for concurrency – User threads * Managed by a thread library – Light weight processes (LWP) * A unit of parallelism within a process Thread library maps user threads into LWPs Several LWPs may be created within a process – Kernel threads * A kernel thread is associated with each LWP The kernel also creates some kernel threads for its own use; e.g., a thread to handle disk I/O • Mapping between threads and LWPs influences parallelism (see Hybrid models’ schematic) Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 56 Copyrightâ2008 Threads in Solaris Mapping between user threads and LWPs is performed by thread library • Each LWP has a KTCB; scheduling is performed by the kernel’s scheduler Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 57 Copyright © 2008 Processes and threads in Linux • Salient features – Linux supports kernel-level threads – Threads and processes are treated alike except at creation * A thread shares the information about memory management, current directory, open files and signal handlers of its parent process; a process does not share any information of its parent – A thread or process contains information about * Its parent * Its deemed parent, to whom its termination should be reported Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 58 Copyright © 2008 Processes and threads in Linux • Process and thread states – Task_running: scheduled or waiting to be scheduled – Task_interruptible: sleeping on an event, but may receive a signal – Task_uninterruptible: sleeping and may not receive a signal – Task_stopped: operation has been stopped by a signal – Task_zombie: operation completed, but its parent has not issued a system call to check whether it has terminated • Interruptibility simplifies implementation of signals Chapter 3: Processes and Threads Dhamdhere:OperatingSystems AConceptưBasedApproach,2ed SlideNo:59 Copyrightâ2008 Processes and threads in Windows • A process is a unit for resource allocation, and a thread is a unit for concurrency Hence each process must have at least one thread in it Interesting thread states: – Standby: Thread has been selected to run on a CPU * Important in a multiprocessor computer system – Transition: Kernel stack has been swapped out Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 60 Copyright © 2008 Thread state transitions in Windows 2000 Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed  Slide No: 61 Copyright © 2008 ... message Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach,  2 ed  Slide No: 26 Copyright © 2008 Event handling actions of an OS Q: Are any arrows missing? Chapter 3: ... housekeeping and statistical analysis Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach,  2 ed  Slide No: 4 Copyright © 2008 Process tree for the real time application... their actions in a desired order – Signals * A signal conveys occurrence of an exceptional situation Chapter 3: Processes and Threads Dhamdhere: Operating Systems— A Concept­Based Approach,  2 ed 

Ngày đăng: 30/01/2020, 01:03

TỪ KHÓA LIÊN QUAN