Docsity

Understanding Processes and Threads: A Deep Dive into Operating Systems, Slides of Operating Systems

Partial preview of the text

Download Understanding Processes and Threads: A Deep Dive into Operating Systems and more Slides Operating Systems in PDF only on Docsity!

Lecture 6

Chapter 4: Threads

Chapter 3: Processes

  • Process Concept
  • Process Scheduling
  • Operations on Processes
  • Interprocess Communication
  • Examples of IPC Systems
  • Communication in Client-Server Systems

Process Control Block (PCB)

Information associated with each process

  • Process state
  • Program counter
  • CPU registers (accumulators, index registers, stack pointers, general purpose registers, etc.)
  • CPU scheduling information (priority, pointers to scheduling queues, etc.)
  • Memory-management information (base and limit registers, page/segment tables, etc.)
  • Accounting information (account numbers, job/process number, time limits, etc.)
  • I/O status information (allocated I/O devices, open files, etc.)

Process Scheduling Queues

  • Multiprogramming : Have some process running at all times to maximize CPU utilization
  • Time-sharing : Switch CPU among processes so frequently that users can interact with each program
  • Process scheduler selects an available process
  • Processes migrate among the various queues
    • Job queue โ€“ set of all processes in the system
    • Ready queue โ€“ set of all processes residing in main memory, ready and waiting to execute
    • Device queues โ€“ set of processes waiting for an I/O device
  • Processes can be described as either:
    • I/O-bound process โ€“ spends more time doing I/O than computations, many short CPU bursts
    • CPU-bound process โ€“ spends more time doing computations; few very long CPU bursts

Process Creation

  • Parent process create children processes, which, in turn create other processes, forming a tree of processes
  • Resource sharing
    • Parent and children share all resources
    • Children share subset of parentโ€™s resources
    • Parent and child share no resources
  • Execution
    • Parent and children execute concurrently
    • Parent waits until children terminate
  • Address space
    • Child duplicate of parent
    • Child has a program loaded into it

Process Termination

  • Process executes last statement and asks the operating system to delete it ( exit ) - Output data from child to parent (via wait ) - Processโ€™ resources are deallocated by operating system
  • Parent may terminate execution of children processes ( abort ) - Child has exceeded allocated resources - Task assigned to child is no longer required - If parent is exiting - Some operating system do not allow child to continue if its parent terminates - All children terminated - cascading termination - In UNIX, init process inherits childrens of an exiting process

Producer-Consumer Problem

  • Paradigm for cooperating processes,

producer process produces information that is consumed by a consumer process

  • unbounded-buffer places no practical limit on the size of the buffer
  • bounded-buffer assumes that there is a fixed buffer size

Interprocess Communication โ€“ Message Passing

  • Mechanism for processes to communicate and to synchronize their actions
  • Message system โ€“ processes communicate with each other without resorting to shared variables
  • IPC facility provides two operations:
    • send ( message ) โ€“ message size fixed or variable
    • receive ( message )
  • If P and Q wish to communicate, they need to:
    • establish a communication link between them
    • exchange messages via send/receive
  • Implementation of communication link
    • physical (e.g., shared memory, hardware bus)
    • logical (e.g., logical properties)

Indirect Communication

  • Messages are directed and received from

mailboxes (also referred to as ports)

  • Each mailbox has a unique id
  • Processes can communicate only if they share a mailbox
  • Primitives are defined as:

send ( A, message ) โ€“ send a message to mailbox A receive ( A, message ) โ€“ receive a message from mailbox A Docsity.com

Indirect Communication

  • Operations
    • create a new mailbox
    • send and receive messages through mailbox
    • destroy a mailbox
  • Mailbox sharing
    • P 1 , P 2 , and P 3 share mailbox A
    • P 1 , sends; P 2 and P 3 receive
    • Who gets the message?
  • Solutions

Buffering

  • Queue of messages attached to the link;

implemented in one of three ways

  1. Zero capacity โ€“ 0 messages Sender must wait for receiver (rendezvous)
  2. Bounded capacity โ€“ finite length of n messages Sender must wait if link full
  3. Unbounded capacity โ€“ infinite length Docsity.com

Examples of IPC Systems - POSIX

  • POSIX Shared Memory
    • Process first creates shared memory segment segment id = shmget(IPC PRIVATE, size, S IRUSR | S IWUSR);
    • Process wanting access to that shared memory must attach to it shared memory = (char *) shmat(id, NULL, 0);
    • Now the process could write to the shared memory Docsity.com

Chapter 4: Threads

  • Overview
  • Multithreading Models
  • Thread Libraries
  • Threading Issues
  • Operating System Examples
  • Windows XP Threads
  • Linux Threads Docsity.com

Objectives

  • To introduce the notion of a thread โ€” a

fundamental unit of CPU utilization that forms the basis of multithreaded computer systems

  • To discuss the APIs for the Pthreads, Win32,

and Java thread libraries

  • To examine issues related to multithreaded

programming