Processes: Definition, Management, States & Communication

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which of the following best describes a process?

  • A program stored on disk
  • A type of memory allocation
  • A program in execution (correct)
  • A hardware component

A thread is a program in execution.

False (B)

What is the purpose of multitasking in an operating system?

To execute multiple processes concurrently by time-sharing the CPU

In the context of processes, I/O-bound processes spend more time waiting for ________ completion than performing computations.

<p>I/O</p> Signup and view all the answers

Match the Chrome browser process types with their functions:

<p>Browser = Manages the user interface and network I/O Renderer = Renders web pages and executes Javascript Plug-in = Handles specific plug-in code and communication</p> Signup and view all the answers

What is the primary function of the process state?

<p>To define the current activity of a process (A)</p> Signup and view all the answers

A process transitions between states only when manually triggered by the user.

<p>False (B)</p> Signup and view all the answers

What is the purpose of a Process Control Block (PCB)?

<p>To represent a particular process in the operating system</p> Signup and view all the answers

The PCB contains the __________, which specifies the address of the next instruction to be executed by the process.

<p>program counter</p> Signup and view all the answers

Match the elements of a PCB with their functions:

<p>Process ID = Unique identifier of a process CPU Registers = Registers used by the process Memory Management Information = Memory-related aspects of a process</p> Signup and view all the answers

What is the main objective of process scheduling?

<p>To maximize CPU utilization and allow user interaction (C)</p> Signup and view all the answers

In a single-processor system, multiple processes can run simultaneously.

<p>False (B)</p> Signup and view all the answers

What is the purpose of the ready queue in process scheduling?

<p>To hold processes residing in main memory and ready for execution</p> Signup and view all the answers

The _________ scheduler selects processes from a pool and loads them into memory for execution.

<p>long-term</p> Signup and view all the answers

Match types of the following schedulers with their descriptions:

<p>Long-term scheduler = Selects processes from the job pool and loads them into memory. Short-term scheduler = Selects from among the processes ready to execute and allocates the CPU to one of them. Medium-term scheduler = Handles the swapped out-processes. and reduces the degree of multiprogramming.</p> Signup and view all the answers

What is the main reason for context switching?

<p>To allow the CPU to switch between different processes (C)</p> Signup and view all the answers

Context switch time is productive time, as it directly contributes to useful work.

<p>False (B)</p> Signup and view all the answers

In the context on context switching, what does saving the context mean?

<p>Saving the current state of a process</p> Signup and view all the answers

The overhead of context switching typically occurs in _________.

<p>milliseconds</p> Signup and view all the answers

Match the steps taken for context switch

<p>Interrupted Process Po = Save process Po state into PCB。</p> Signup and view all the answers

What is the term for a process that creates new processes?

<p>Parent process (B)</p> Signup and view all the answers

Child processes always have the same process ID (PID) as their parent process.

<p>False (B)</p> Signup and view all the answers

What is the significance of the pid variable?

<p>Process identifier</p> Signup and view all the answers

A process in Unix can terminate by calling the _______ system call.

<p>exit()</p> Signup and view all the answers

Match the resource sharing

<p>Address Space = Child can load a new program. Shared resources = Parent process continues or waits</p> Signup and view all the answers

What is inter-process communication (IPC)?

<p>Communication between processes running concurrently (D)</p> Signup and view all the answers

Independent processes can affect or be affected by other processes in the system.

<p>False (B)</p> Signup and view all the answers

What are the advantages or needs for Inter-Process Communication?

<p>Information Sharing, Computation Speed Up, Convenience</p> Signup and view all the answers

In IPC, a ________ is defined as an endpoint for communication over a network.

<p>socket</p> Signup and view all the answers

Match the following IPC methods with their description:

<p>Message Passing = Data exchange through messages Shared Memory = Establish memory shared between processes</p> Signup and view all the answers

In the Producer-Consumer model, what happens when produced items arrive faster than they are consumed?

<p>Buffering is needed (C)</p> Signup and view all the answers

In the shared memory model for IPC, processes communicate by exchanging messages through a mailbox.

<p>False (B)</p> Signup and view all the answers

What is the role of buffers in the producer-consumer model?

<p>Store items produced by producer and consumed by consumer</p> Signup and view all the answers

In message passing, the send() and recv() operations can be ______ or non-blocking.

<p>blocking</p> Signup and view all the answers

Match these statements

<p>Shared Memory = Requires more time-consuming task of kernel intervention Message Passing = Better performance than shared memory with multi cores</p> Signup and view all the answers

Which of the following best describes pipes?

<p>A communication channel (D)</p> Signup and view all the answers

Pipes are bidirectional by default, allowing data to flow in both directions simultaneously.

<p>False (B)</p> Signup and view all the answers

How can standard I/O redirection create a pipe?

<p>| permits the output of a program to become another program's input</p> Signup and view all the answers

Using standard I/O redirection, > redirects the output of a program or a command into a specified ____________.

<p>file</p> Signup and view all the answers

Match each file dscriptor using Pipes:

<p>fd[0] (File descriptor 0) = reading fd[1] (File descriptor 1) = writing</p> Signup and view all the answers

When a process terminates but its PCB remains in memory, what is this process called?

<p>Zombie process (C)</p> Signup and view all the answers

Flashcards

What is a Process?

A program in execution; an instance of a program running.

What is a Thread?

A basic unit of CPU utilization, consisting of a program counter, stack, and a set of registers.

What is Multitasking?

Executing multiple processes concurrently, giving the illusion of parallelism.

What is Process State?

The current activity of a process (e.g., new, running, waiting, ready, terminated).

Signup and view all the flashcards

How many process states are there?

Five: New, Running, Waiting, Ready, and Terminated.

Signup and view all the flashcards

What is a PCB? (Process Control Block)

A data structure containing information about a process, used by the OS to manage it.

Signup and view all the flashcards

What is Context Switch?

The act of switching the CPU from one process to another.

Signup and view all the flashcards

What is a Process ID?

A unique identifier for each process.

Signup and view all the flashcards

What is Process State?

The state a process is in at a particular moment (e.g., new, waiting).

Signup and view all the flashcards

What is Program Counter?

Address of the next instruction to be executed.

Signup and view all the flashcards

What are CPU Registers?

Registers used by a process.

Signup and view all the flashcards

What is CPU Scheduling Information?

Priority of the processes, to the scheduling queue

Signup and view all the flashcards

What is Memory Management Information?

Memory used by the process.

Signup and view all the flashcards

What is Accounting Information?

Resources used by the process (CPU, time, memory).

Signup and view all the flashcards

What is I/O Status Information?

I/O devices assigned to a process.

Signup and view all the flashcards

What is Process Scheduler?

The OS component that selects which process to run next.

Signup and view all the flashcards

What are common Scheduling Queues?

Job, Ready, and Device Queues.

Signup and view all the flashcards

What does a Long-Term Scheduler do?

Manages long-term scheduling of processes.

Signup and view all the flashcards

What does a Short-Term Scheduler do?

Selects processes from ready queue.

Signup and view all the flashcards

What does a Medium-Term Scheduler do?

In charge of swapped out processes.

Signup and view all the flashcards

Context switch

Context Switch and Performance

Signup and view all the flashcards

What is Process Creation?

A process creates another, the parent continues, the child is new.

Signup and view all the flashcards

What happens after process creation?

The parent waits or continues concurrently.

Signup and view all the flashcards

What is Process Termination?

A process finishes execution.

Signup and view all the flashcards

What is Inter-Process Communication (IPC)?

Communicate and synchronise different processes to execute simultaneously .

Signup and view all the flashcards

What types of processes are there?

Processes may be independent or cooperating.

Signup and view all the flashcards

What are Independent Processes?

Independent processes do not affect each other.

Signup and view all the flashcards

What are Cooperating Processes?

Cooperating processes affect or are affected by each other.

Signup and view all the flashcards

What is Inter-Process Communication (IPC)?

Communicate using shared memory or message passing.

Signup and view all the flashcards

What is the need for Inter-Process Communication?

Speed up computation, Share information, provide Convenience.

Signup and view all the flashcards

What is Shared Memory IPC?

Use shared memory regions to exchange data.

Signup and view all the flashcards

What is Message Passing IPC?

Exchange messages between processes.

Signup and view all the flashcards

What is Pipes?

Is a connection that allows to pass data from one process into another

Signup and view all the flashcards

What is message Socket?

Is a form of communication for data by passing packets

Signup and view all the flashcards

What are Pipes?

One writes, the other reads (unidirectional).

Signup and view all the flashcards

What are Process job/ready Queue

A job queue and a ready queue.

Signup and view all the flashcards

What are Process Queues?

Processes organized into job, ready, and device queues.

Signup and view all the flashcards

What are Producer-Consumer Model?

One process produces data and the other consumes it.

Signup and view all the flashcards

What are unidirectional flows?

Pipes.

Signup and view all the flashcards

Using Command Pipes in CLI

The output of a program becomes the input of the next.

Signup and view all the flashcards

Study Notes

  • Education is a powerful tool for changing the world, as stated by Nelson Mandela

Processes

  • Covers process definition, management, states, scheduling, context switching, and inter-process communication
  • Learning outcomes include defining processes, differentiating between processes and threads, understanding multitasking and process states
  • Aims to teach process operations (creation, termination, communication) and the Producer-Consumer model

Process Definition and Management

  • Program source code written in a high-level language like C++/Java is transformed into machine-readable code
  • A compiler transforms the code that operating system loads into computer memory for program execution, allocating resources as needed

Process vs. Thread

  • A process is a program in execution
  • A thread is a unit of execution within a process
  • A process can have one or more threads

Multitasking

  • Processes spend time on I/O activities, which is slower than CPU processing
  • Multitasking happens when the OS runs multiple processes concurrently by time-sharing hardware

Chrome Browser Example

  • Chrome uses multiple processes: a browser process for the UI and network I/O, renderer processes for web pages and HTML parsing, and plug-in processes like Adobe Flash Player
  • Adobe Flash Player enables viewing multimedia content, executing rich internet applications, and streaming audio/video

Process State

  • The state is defined by the current activity
  • When executing, a process changes states

Five Process States

  • New: The process is being created
  • Running: Instructions are being executed
  • Waiting: Waiting for an event (I/O completion or a signal)
  • Ready: Waiting to be assigned to a processor
  • Terminated: The process has finished execution

Diagram of Process State

  • Illustrates transitions between New, Ready, Running, Waiting, and Terminated states via events like interrupts, scheduler dispatch, and I/O

Process Control Block (PCB)

  • Each process runs in the OS and is tracked via a PCB - sometimes called a task control block
  • PCB represents a process in the Operating System

PCB Contents

  • Process ID: Unique identifier
  • Process State: Current state (New, Waiting, etc.)
  • Program Counter: Points to the next instruction to be executed
  • CPU Registers: Registers used by process
  • CPU Scheduling Information: Process priority, scheduling queue
  • Memory Management Information: Memory used by the process
  • Accounting Information: Resources used (CPU, time, memory)
  • I/O Status Information: I/O devices assigned

PCB in Linux

  • Linux maintains a doubly-linked list of processes using the C structure task_struct

Process Scheduling

  • Multiprogramming maximizes CPU use by running a process all the time
  • Time sharing switches the CPU between processes, and allows user interaction
  • The process scheduler makes program accessible for the CPU to run it

Single Processor System

  • Only one process can run at the same time on a computer

Scheduling Queues

  • Job Queue: Contains all processes in the system
  • Ready Queue: Contains processes residing in main memory, ready and wait time

Schedulers

  • Long-term (job) scheduler: Selects processes from a storage pool and loads them into memory
  • Short-term (CPU) scheduler: Selects from ready processes and allocates the CPU
  • Medium-Term Scheduler: Part of swapping, removes processes from memory to reduce multiprogramming, manages swapped-out processes

Context Switch

  • The operating system has to save the current context of the process that's currently running on the CPU so that it can restore that context when its processing is done, suspending the process and then resuming it
  • The PCB stores it in the context

Concept of Context

  • Interrupts cause the OS to switch the CPU from the current task to a kernel routine
  • The system saves the current process context (state) for later restoration

Context Switch Details

  • A context switch occurs when a CPU core switches from one process to another
  • The OS saves the context of the current process and loads the context of the new process
  • A scheduler decides when to perform a context switch and selects the next process, this occurs in the kernel

Context Switch Performance

  • Context switch time is pure overhead
  • Speed varies depending on memory speed and registers
  • Typical speeds are milliseconds

Operation on Processes: Creation

  • Via a create process-system call, a process can create several new processes
  • The creating process is considered the parent process, and the new processes are called the children.
  • Each process has a unique pid (process identifier), usually an integer

Process Creation Options

  • Parent can execute concurrently with its children

  • The parent can wait until some or all of its children are terminated

  • The child is a duplicate of the parent

  • The child uses a new program loaded

Process Creation in UNIX and Windows:

  • UNIX programs use fork() to create a new process, exec() to replace its image, exit() to terminate, and wait() for child processes
  • Windows uses CreateProcess() to specify the command to execute in a child process; it does not support fork()

Process Termination

  • A process ends by calling exit()
  • The parent recovers the status via wait().
  • The PCB waits until the parent calls wait() and becomes a zombie process
  • The kernel can also "kill" a process

Inter-Process Communication (IPC)

  • Concurrent processes are either independent or cooperating
  • IPC is needed in cooperating processes

Needs for Inter-Process Communication

  • Information sharing
  • Computation speedup
  • Convenience

IPC Methods

  • Shared Memory: A shared memory region is established with cooperating processes
  • Message Passing: Uses messages exchanged between processes
  • Pipes: Functions like shared files, with one process writing and another reading (unidirectional)
  • Sockets: Endpoints for communication, identified by IP address and port number

Producer-Consumer Model

  • A common IPC pattern involves a producer and a consumer which run concurrently
  • Buffering is needed to handle variable production/consumption rates
  • A buffer has a limited size, so it's also called a bounded-buffer problem

Example Practical Implementations

  • I/O device drivers act as producers, collecting input that applications (consumers) process
  • Print spooling involves applications sending files to a folder
  • After this a spooler process sends them to the printer one at a time

Shared Memory

  • Different memory accessible by different processes in a bidirectional manner

Shared Memory: Consumer-Producer Model

  • Uses a memory area that the accessing processes use
  • Producer and consumer utilize a shared buffer

Key Concepts

  • Processes have unique memory spaces
  • The OS provides special ways to allocate memory that can be shared across processes
  • The code given in the previous slide is not synchronized!!

Key Considerations of shared memory and Message passing

  • Shared memory allows processes to allocate memory for use in several processes
  • OS provides special ways to allocate this memory, these have to be created explicitly with more configuration than message passing
  • Sharing memory only works with systems the memory across them, and this implementation requires a kernel

Message Passing

  • Uses direct links with send(pid, msg) and recv(pid, msg)
  • Uses indirect links with mailboxes send(mbox, msg) and recv(mbox, msg)
  • send() and recv() can be blocking or non-blocking, some apps utilize these for synchronization

Message Passing: Consumer-Producer Model

  • Consumer reads from the producer
  • Producer sends message to consumer

Characteristics of Shared Memory and Message Passing

  • Shared memory requires system calls only to establish shared regions, then accesses work as routine memory accesses
  • Message passing requires more kernel intervention, is useful for small data, and is easier to implement in distributed systems

Pipes

  • Acts like having an intermediate file where one process writes and the other process reads, pipes exist in main memory
  • The system calls used to read and write to/from a pipe mirror file accessing
  • Examples are READ() and WRITE()

Two pipe types

  • Ordinary pipe in UNIX (Anonymous pipes in Windows) work by creating a parent that connects to a child process to create a line of communication
  • Named pipe - also known as AKA FIFO makes information accessible by process
  • In both cases Pipe is Unidirectional, but two pipes can be added to ensure that you can create two lines of pipes in different directions

Pipes In Code

  • In code a descriptor fd[0] is for reading and fd[1] is for writing
  • If the program is connected, the data written in fd[1] can be read from fd[0]

Pipes in Command Line Interface (CLI)

  • CLI creates pipes between two programs where you can redirect input and output
  • You can redirect the output of a command into a specified file by adding the redirector, represented by ">"
  • The Pipe symbol "|" pipes the output of the first command, and pipes it directly as in input into the second command

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser