Processes and Threads

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Which of the following is the most accurate definition of a process?

  • A program in execution. (correct)
  • A static entity.
  • A program stored on disk.
  • A set of instructions.

A program is a dynamic execution of a process.

False (B)

What is the purpose of the process identifier (PID)?

To uniquely identify and manage a process.

A process may create several new processes via a ______ system call.

<p>create-process</p> Signup and view all the answers

Match the following process termination conditions with their types:

<p>Normal exit = Voluntary Error exit = Voluntary Fatal error = Involuntary Killed by another process = Involuntary</p> Signup and view all the answers

Which section of a process's memory contains global variables?

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

When a process is in the 'Blocked' state, it is actively using the CPU.

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

What data structure is used by the OS to maintain information about each process?

<p>Process Control Block (PCB)</p> Signup and view all the answers

The act of stopping one process and starting another is known as _______.

<p>context switching</p> Signup and view all the answers

Which of the following is NOT a typical cause for process creation?

<p>Automatic memory defragmentation (D)</p> Signup and view all the answers

Context switching is a purely productive activity for the system.

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

Name three pieces of information stored within a Process Control Block (PCB).

<p>Process state, program counter, CPU registers</p> Signup and view all the answers

In UNIX, the system call used to terminate another process is called ______.

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

Which process state indicates that a process is waiting to be assigned to a processor?

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

A parent process cannot monitor the execution of its child processes.

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

What is the difference between a program and a process?

<p>A program is a static set of instructions, while a process is the execution of those instructions.</p> Signup and view all the answers

In process creation, the duplicate of the parent process is called the _______.

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

Which of the following is NOT a reason for process termination?

<p>Process migration (A)</p> Signup and view all the answers

The 'Heap' section of a process is used for storing temporary data like function parameters.

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

Briefly describe what happens during a context switch.

<p>The OS saves the state of the current process and restores the state of a new process.</p> Signup and view all the answers

Processes that interact with users are known as ______ processes.

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

Which of the following actions would cause a transition from the 'Blocked' state to the 'Ready' state?

<p>An event the process was waiting for occurs. (A)</p> Signup and view all the answers

A process can only be in one state at a time.

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

What is the main function of the 'Text' section in a process's memory layout?

<p>To store the program's executable code</p> Signup and view all the answers

Processes that are not associated with particular users but have some specific function are called ______ processes.

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

Which of the following is the most accurate description of a thread?

<p>A lightweight process that shares resources with other threads. (D)</p> Signup and view all the answers

Threads within the same process have independent address spaces.

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

What is multithreading?

<p>Allowing multiple threads in the same process.</p> Signup and view all the answers

A thread has a program ________ that keeps track of which instruction to execute next.

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

Which of the following resources is typically shared by all threads within a process?

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

If one thread in a process is blocked, the entire process is blocked.

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

List two advantages of using threads.

<p>Responsiveness, Resource Sharing, Economy, Scalability</p> Signup and view all the answers

______ is an API used to create and manage threads

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

Which of the following is NOT a basic thread library?

<p>C++ threads (D)</p> Signup and view all the answers

Implementing threads in user space makes the kernel aware of the existence of threads.

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

What is the main advantage of implementing threads in kernel space?

<p>If one thread blocks, the kernel can schedule another thread in the same process.</p> Signup and view all the answers

______ occurs when a system can perform more than one task simultaneously.

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

According to Amdahl's Law, what factor has a disproportionate effect on performance gained by adding additional cores?

<p>Serial portion of an application (C)</p> Signup and view all the answers

Data parallelism involves dividing tasks among multiple cores, whereas task parallelism divides data among multiple cores.

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

Explain the difference between concurrency and parallelism.

<p>Concurrency is when multiple tasks can start, run, and complete in overlapping time periods. Parallelism is when multiple tasks can run simultaneously.</p> Signup and view all the answers

Flashcards

What is a process?

A program in execution; an activity with a program, input, output, and state.

Process Control Block (PCB)

A data structure maintained by the OS for every process, storing information about it.

Context Switching

Stopping one process and starting another, saving/restoring states.

Three Process States

Running, Ready, and Blocked

Signup and view all the flashcards

Process Stack

The process Stack contains temporary data, parameters, return addresses, and local variables.

Signup and view all the flashcards

Process Heap

The process Heap is dynamically allocated memory during a process run time.

Signup and view all the flashcards

What is a Thread?

A single sequence stream within a process; a light weight process.

Signup and view all the flashcards

Threads vs Processes: Independence

Thread shares resources or is part of a process, while processes are typically independent.

Signup and view all the flashcards

Multithreading

Multiple threads within a process for concurrent execution of tasks.

Signup and view all the flashcards

Two ways to implement threads

User-level and Kernel-level

Signup and view all the flashcards

Benefits of Multithreading

Improved responsiveness, resource sharing, economy, and scalability.

Signup and view all the flashcards

Data parallelism

divides the data up amongst multiple cores and performs the same task on each subset of the data.

Signup and view all the flashcards

Task parallelism

divides the different tasks to be performed among the different cores and performs them simultaneously.

Signup and view all the flashcards

Thread library

Provides an API to create and manage threads.

Signup and view all the flashcards

What is context switching?

the OS save the state of an Active Process and restore the state of the new process.

Signup and view all the flashcards

Study Notes

Processes and Threads

  • Operating systems in modern systems can load multiple programs into memory and execute them simultaneously.
  • The concept of a "process" emerged to manage program execution.
  • A process is essentially a program in execution.
  • Processes need an input, output, and a state.

Process Layout

  • When a program loads into memory as a process, it divides into four sections: stack, heap, text, and data.
  • Stack sections contain temporary data.
  • Heap allocations occur dynamically during runtime.
  • Text sections includes values of program counters and the contents of the processor's registers.
  • Data sections contain global and static variables.

Program vs Process

  • A program is a static entity.
  • A process is where a program goes when starting execution, and needs a CPU to execute.

Process Creation

  • A process can create new processes using a create-process system call.
  • The creating process is the "parent process".
  • The new processes is the "children" of the parent process.
  • Processes are identified and managed via a process identifier (PID).
  • A new process is a duplicate of that process
  • The "child" process replaces the parent process copy with the code the child process has to execute.
  • The child has a program loaded into a new program.

Process Creation - System Initialization

  • When an OS boots up, multiple processes are are typically created.
  • Foreground processes interact with human users
  • Background processes aren't associated with users, but have specific functions. Examples include accepting mail, driver updates, and network configurations.

Process Creation - Execution of a Creation System Call

  • A running process can request a create-process system call.
  • New processes helps a running process do its job.
  • Creating new processes is useful when work is easily broken down into related, independent tasks.
  • A process fetching large data amounts can create one process for fetching and another for execution.

Process Creation - User Request

  • Users can start programs in interactive systems via a command, or a double click.
  • Either one of these actions makes a new process to run the selected program.

Process Creation - Initiation of a Batch Job

  • Users submit batch jobs to a system, potentially remotely.
  • The operating system creates a new process when it has enough resources to run another job.

Process Termination

  • Processes will eventually terminate due to: Normal exit, error exit, fatal error, or termination by another process.
  • Normal exit terminations occur when processes have finished work.
  • Error exit terminations occur if the program finds a fatal error.
  • The another reason for termination is caused by the process, often due to a program bug.
  • Processes may terminate with a system call that tells the OS to terminate the processes, if they have permissions.

Process States

  • The process state changes while executing.
  • Three main states a process experiences includes running, ready, and blocked.
  • In the running state, program instructions execute.
  • The ready state is where processes waits to be assigned to a processor.
  • The blocked state is where processes waits for event.

Process States

  • Transition 1 means a process blocks while waiting for an event.
  • Transition 2 happens when the scheduler picks another process to have CPU time.
  • Transition 3 happens when the scheduler picks the first process to get the CPU and run again.
  • Transition 4 means that an event has occurred, and the blocked process is awakened.

Five Process States

  • The five process states include: new, ready, running, waiting, and terminated.
  • A new process is being created.
  • A ready process is waiting to run, and is temporarily is stopped let another process run.
  • A running process is actively using the CPU.
  • A blocked/waiting process can't run until external events happen.
  • A terminated process has finished executing.

Process Control Block (PCB)

  • A process control block (PCB) is a data structure maintained by the OS for every process.
  • PCBs store information about processes.
  • Each PCB has an integer process ID (PID).
  • The PCB is retained through the lifetime of the process
  • PCB is deleted once a process completes

PCB Contents

  • The process identifier in the PCB uniquely identifies processes.
  • The process state shows the current state.
  • The program counter is a pointer to the next instruction's address for execution.
  • CPU registers are stored here, where processes needs stored when running.
  • Details regarding the allocation of I/O devices goes there.
  • Accounting details include the amount of CPU used, and the time limits.

Context Switching

  • Context switching means stopping one process, then starting another.
  • During an event, the OS saves the current process state and restores the state of the next process.
  • Context switching is considered overhead, and doesn't perform a useful work.

Context Switching Actions

  • OS saves the running process's context the in PCB.
  • Then, it reloads a context from a new process's PCB.
  • Finally, control returns to proceed with the new process.

Processes - Implementation

  • To implement the process model, the OS maintains a process table.
  • The process table has one entry per process.
  • PCB Contains information associated with each process.
  • The process table stores process control blocks (PCBs), known as task control blocks.
  • A CPU scheduling information is stored for each process, with process priorities, and pointers to queues.
  • Accounting details includes the amount of CPU/real time used.
  • I/O status, and event information is also tracked here.

Thread Concepts

  • The process model has two independent concepts: resource grouping, and execution.
  • Resources may include open files, child processes, pending alarms, signal handlers, and accounting details.
  • Thread implementation makes resources easier to manage.
  • A thread is a light weight process created by a process.
  • It's a stream of instructions within a process.

Multiple Threads

  • The thread has a program counter to track of which instruction is to execute next.
  • It has registers holding current function variables.
  • There's a stack holding the execution history.
  • Processes group resources; threads are the scheduled entities for the CPU.
  • Multithreading means multiple threads exist in the same process.
  • Threads share the code/data sections, and OS resources.

Processes and Threads - Similarities

  • Both share CPU, only one thread or process is active at a time.
  • Like processes, threads within a process execute sequentially.
  • Like processes, threads can create children.
  • Like processes, if one thread is blocked, another can run.

Processes and Threads - Differences

  • Threads are not independent of one another.
  • All threads have access every address in the task.
  • Threads are often designed to assist one another.
  • Processes are more independent.

Multithreading Usage

  • Applications require multiple activities occuring at the same time.
  • Decomposing applications into multiple sequential quasi-parallel threads simplifies the programming model.
  • Threads are easier to create and destroy comparing with processes.
  • When having multiple threads in applications, this may increase performance.
  • Threads make better use of multiple CPUs.

Thread Libraries

  • Thread libraries allows programmers to create, and manage threads.
  • Three main thread libraries are: POSIX pthreads, Windows threads, and Java threads.
  • POSIX threads may either be a user, or kernel library.
  • Solaris. Linux, and macOS implement pthreads.
  • Windows threads have kernel-level library.
  • Java threads depend on OS and the hardware the JVM is running, being either Pthreads, or Windows depending on the system.

Thread Implementation

  • There are primarily two types of ways to implement threads: User Space and Kernel space.
  • "User Space" implementations store all data and code in user space.
  • User space allows each process to have customized scheduling algorithms
  • "Kernel Space" implementations store all code and data structures inside the Kernel space.

Benefits - User Space Implementation

  • Thread switching calls a run-time system procedure, which is faster than trapping the kernel
  • Easy to customize scheduling algorithms.

Disadvantages - User Space Implementation

  • There exists issues with blocking system calls.
  • How should page faults be handled?

Implementation of threads in Kernel space

  • A kernel threads implementation means
    • All code and data structures reside in kernel space
    • Calling an implementation functions needs for a system call is triggered
    • The kernel is aware of the existing threads

Benefits - Kernel Space Implementation

  • Might block a thread, implemented as system calls.
  • If one thread in a process causes a page fault, the kernel can check another process while waiting.
  • Solve some but not all synchronization problem.

Hybrid Implementations

  • Hybrid Implementation uses kernel-level threads, and then multiplexes user-level threads on some, or all of the kernel threads.

Benefits of Multithreading

  • Responsiveness through continued execution.
  • Threads share resources, and memory which makes it easier.
  • Cheaper than process creation
  • Multithreading utilizes multiprocessor architectures.

Multicore Programming

  • Modern computer architecture uses CPUs with multiple cores.
  • Multi-core programming utilizes computing cores for improved concurrency.
  • With Multicore Systems, Challenges include: dividing tasks, balancing, data splitting, data dependency, and properly testing/debugging.
  • Parallelism means the system can perform more than one task simultaneously.
  • Concurrency means that the system has more than one task progressing.
  • Single processor/core, scheduler providing concurrency.

Concurrency vs. Parallelism

  • Concurrent execution, running one process at a time on a single core.
  • Parallel execution means running multiple processes at the same time.

Amdahl's Law

  • Identifies performance gains from adding cores to an application with serial/parallel components.
  • When N approaches infinity speed approaches 1/S.
  • Where S is the non-parallelizable (serial) portion, and N is the number of processing cores.
  • Serial portions of applications disproportionately limits performance gained from additional cores

Multicore Programming

  • Data parallelism distributes data to multiple cores to perform the same task on subsets of data.
  • Task parallelism divides tasks among cores, so cores perform simultaneously.
  • Applications commonly use a hybrid approach combining task and data parallelism.

Multithreading Models

  • Reading assignment
  • Amdahl's Law (serial and parallel components)
  • Multithreading Models
  • Common ways of establishing multithreading models such a relationship are:
    • Many-to-One
    • One-to-One
    • Many-to-Many
  • Implicit Threading
  • Thread Pools
  • Thread Cancellation

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