Operating Systems: Processes

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 NOT one of the four principal events that cause processes to be created?

  • Process deletion (correct)
  • System initialization
  • A user request to create a new process
  • Execution of a process creation system call by a running process

A process in the 'Ready' state is actively using the CPU at that instant.

False (B)

List the typical conditions that can lead to the termination of a process.

Normal exit, error exit, fatal error, killed by another process.

A process transitions to the ________ state when it is unable to run until some external event occurs.

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

Match the process state with its description:

<p>Running = Actively using the CPU Ready = Runnable, temporarily stopped Blocked = Unable to run until an external event</p> Signup and view all the answers

Which of the following process management fields isn't part of a typical process table entry?

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

In the lowest level of the operating system, assembly language procedures are only used to save registers.

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

Explain the relationship between the degree of multiprogramming and CPU utilization.

<p>CPU utilization generally increases with the degree of multiprogramming but plateaus as the number of processes increases.</p> Signup and view all the answers

CPU utilization can be modeled using the formula: CPU utilization = 1 − $p^n$, where 'p' is the fraction of time a process is waiting for I/O, and 'n' is the ________

<p>degree of multiprogramming</p> Signup and view all the answers

Match each element with its corresponding description in the context of process management within an operating system:

<p>Registers = Storage locations within the CPU used for quickly accepting, storing, and transferring data and instructions Program Counter = A register that holds the address of the next instruction to be executed Stack Pointer = A register that points to the top of the stack</p> Signup and view all the answers

In a multithreaded web server, what is the primary role of the dispatcher thread?

<p>Assigning work to worker threads (B)</p> Signup and view all the answers

A single-threaded process can achieve parallelism.

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

Describe the key difference between a thread and a process.

<p>Threads share the same address space, while processes have separate address spaces.</p> Signup and view all the answers

In the classical thread model, each thread has its own ________, whereas items like address space and global variables are shared among all threads in a process.

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

Match the item with whether it's a 'per process item' or a 'per thread item'.

<p>Program counter = Per thread item Address space = Per process item Open files = Per process item Stack = Per thread item</p> Signup and view all the answers

Which of the following Pthreads function calls is used to terminate the calling thread?

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

The pthread_join function releases the CPU to let another thread run.

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

What is the primary purpose of the pthread_attr_init function in Pthreads?

<p>To create and initialize a thread's attribute structure.</p> Signup and view all the answers

In Pthreads, the ________ function is used to release the CPU and allow another thread to run.

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

Match the Pthreads function with its description:

<p>Pthread_create = Creates a new thread Pthread_exit = Terminates the calling thread Pthread_join = Waits for a specific thread to exit</p> Signup and view all the answers

What is a race condition?

<p>A condition where multiple processes are trying to access and modify shared memory concurrently (A)</p> Signup and view all the answers

To avoid race conditions, it is okay to make assumptions about the speeds or the number of CPUs.

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

What are the four requirements to avoid race conditions?

<p>Mutual exclusion, no assumptions about CPU speed, no blocking outside critical regions, no indefinite waiting.</p> Signup and view all the answers

A ________ is a section of code where shared resources are accessed, and where it is crucial to avoid race conditions.

<p>critical region</p> Signup and view all the answers

Match each of the following race condition requirements with its description:

<p>Mutual exclusion = No two processes may be simultaneously inside their critical regions. No CPU assumptions = No assumptions may be made about speeds or number of CPUs. Progress = No process running outside its critical region may block other processes.</p> Signup and view all the answers

What is the problem with the strict alternation solution for mutual exclusion?

<p>It prevents a process from entering its critical region if the other process doesn't need to enter its own (C)</p> Signup and view all the answers

The 'sleep' and 'wakeup' primitives always prevent race conditions in producer-consumer problems.

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

Explain how semaphores can be used to solve the producer-consumer problem.

<p>Semaphores can manage access to the buffer and signal when it's full or empty, coordinating producer and consumer actions.</p> Signup and view all the answers

A semaphore is a protected variable that can signal between threads in the same process by using two atomic operations, namely ________ and ________.

<p>down, up</p> Signup and view all the answers

Match each term with its description in the context of process synchronization:

<p>Semaphore = A protected variable used for signalling between threads Mutex = A lock that provides exclusive access to a shared resource Critical Region = A code segment where shared resources are accessed</p> Signup and view all the answers

Which Pthreads call is used to acquire a lock, blocking if the mutex is already locked?

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

pthread_mutex_trylock will block if the mutex is already locked.

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

What is the purpose of condition variables in Pthreads?

<p>Condition variables allow threads to block and wait for a specific condition to become true, signaling other threads when the condition changes.</p> Signup and view all the answers

In Pthreads, the pthread_cond_wait function allows a thread to block until ________.

<p>a signal</p> Signup and view all the answers

Match the Pthreads calls relating to condition variables with their descriptions:

<p>Pthread_cond_signal = Signal another thread and wake it up Pthread_cond_broadcast = Signal multiple threads and wake all of them Pthread_cond_wait = Block waiting for a signal</p> Signup and view all the answers

In which type of systems is throughput an important scheduling goal?

<p>Batch systems (D)</p> Signup and view all the answers

In real-time systems, predictability is more crucial than meeting deadlines.

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

What is the key difference between preemptive and non-preemptive scheduling?

<p>Preemptive scheduling can interrupt a running process, while non-preemptive scheduling allows a process to run until completion or voluntary release.</p> Signup and view all the answers

The shortest job first scheduling algorithm is an example of an algorithm used in ________.

<p>batch systems</p> Signup and view all the answers

Match each scheduling type with the primary goal:

<p>Batch = Maximize throughput Interactive = Respond to requests quickly Real-time = Meeting deadlines</p> Signup and view all the answers

Flashcards

The Process Model

A model where multiple processes run seemingly simultaneously on a single CPU by rapidly switching between them.

Process Creation

Caused by system initialization, process creation call, user request or initiation of batch job.

Process Termination

Occurs due to normal exit, error exit, fatal error or being killed by another process.

Process States

States include: running (using CPU), ready (runnable), blocked (waiting for external event).

Signup and view all the flashcards

Race Condition

A situation where multiple processes or threads access shared data concurrently, and the final outcome depends on the order of execution.

Signup and view all the flashcards

Critical Region

A section of code where shared resources are accessed; mutual exclusion is required to avoid race conditions.

Signup and view all the flashcards

Strict Alternation

A flawed approach to mutual exclusion where processes take turns accessing a critical region, but progress is blocked if one process is delayed.

Signup and view all the flashcards

Sleep and Wakeup

A low-level synchronization primitive that can cause a process to block (sleep) until another process wakes it up.

Signup and view all the flashcards

Semaphore

A synchronization primitive that uses an integer value to control access to shared resources. Can block processes.

Signup and view all the flashcards

pthread_yield

A Pthread function that releases the CPU to allow another thread to run.

Signup and view all the flashcards

pthread_create

A Pthread function that creates a new thread.

Signup and view all the flashcards

Threads

Lightweight processes within a process, sharing address space.

Signup and view all the flashcards

pthread_mutex_init

A Pthread function to create a mutex variable.

Signup and view all the flashcards

pthread_mutex_lock

A Pthread function to acquire a lock; blocks if unavailable.

Signup and view all the flashcards

pthread_mutex_unlock

A Pthread function to release a lock.

Signup and view all the flashcards

pthread_cond_init

A Pthread function to initialize a condition variable.

Signup and view all the flashcards

pthread_cond_wait

A Pthread call that blocks a thread until a signal.

Signup and view all the flashcards

pthread_cond_signal

A Pthread function to signal a waiting thread.

Signup and view all the flashcards

pthread_cond_broadcast

A Pthread function to signal all waiting threads.

Signup and view all the flashcards

Scheduling algorithm goals

Seeks to give each process a fair share of the CPU, enforce policies, and keep the system busy.

Signup and view all the flashcards

First-Come First-Served

Scheduling method where process get CPU in order of arrival.

Signup and view all the flashcards

Shortest Job First

Scheduling method where shortest jobs run first to minimize waiting.

Signup and view all the flashcards

Preemptive

Execution can be interrupted.

Signup and view all the flashcards

Non-preemptive

Execution runs to completion.

Signup and view all the flashcards

Round-Robin Scheduling

Interactive system scheduling algorithm gives equal time slices to each process.

Signup and view all the flashcards

Priority scheduling

Interactive system scheduling algorithm; processes run based on assigned importance.

Signup and view all the flashcards

Real-time system scheduling

Algorithms used in systems requiring tasks to be completed by specific times.

Signup and view all the flashcards

Dining Philosophers

A classic concurrency problem involving resource allocation and deadlock.

Signup and view all the flashcards

Readers and Writers

Classic concurrency problem where access to DB is by readers (shared) or writer (exclusive).

Signup and view all the flashcards

Study Notes

Process Model

  • Multiprogramming allows multiple programs to run concurrently
  • A process switch enables transitioning between processes
  • A conceptual model consists of four independent, sequential processes
  • Only one program stays active at any given moment

Process Creation

  • System initialization starts processes
  • A running process can make a system call to create another process
  • A user can request a new process be created
  • Initiation of a batch job creates processes

Process Termination

  • Normal exit is a voluntary termination
  • Error exit is a voluntary termination
  • Fatal error is an involuntary termination
  • It is possible for a process to be killed by another process involuntarily

Process States

  • A process can be in one of three states at a time:
  • Running: Currently using the CPU
  • Ready: Runnable but temporarily stopped
  • Blocked: Unable to run until an external event occurs
  • A process can transition between running, blocked and ready states
  • The lowest layer of a process-structured OS handles interrupts and scheduling
  • Sequential processes reside above that layer

Implementation of Processes

  • Process management includes registers, program counter, program status word, stack pointer, process state, priority, scheduling parameters, process ID, parent process, process group, signals, start time, CPU time used, children's CPU time, and next alarm time
  • Memory management includes pointers to text, data, and stack segment information
  • File management includes root directory, working directory, file descriptors, user ID, and group ID

Interrupt Handling

  • A hardware stacks its program counter
  • The hardware loads a new program counter from the interrupt vector
  • Assembly language procedures save registers and sets up a new stack
  • A C interrupt service reads/buffers input
  • A scheduler decides which process to run next
  • A C procedure returns to the assembly code
  • Assembly language procedures start a new current process

Multiprogramming Model

  • CPU utilization is a function of the number of processes in memory
  • CPU utilization = 1 – p^n

Thread Usage

  • A multithreaded Web server has a dispatcher thread, worker thread, and Web page cache
  • The dispatcher thread gets requests and hands off work
  • The worker thread waits for work, looks for pages in cache, reads from disk if needed, and returns pages

Threads vs Processes

  • Threads feature parallelism with blocking system calls
  • Single-threaded processes don't allow parallelism with blocking system calls
  • Finite-state machines allow parallelism with nonblocking system calls and interrupts

Classical Thread Model

  • Process describes any program that is in execution
  • A process can have multiple threads inside it
  • Each thread has its own stack
  • Per-process items include address space, global variables, open files, child processes, pending alarms, signals and signal handlers, and accounting information
  • Per-thread items include program counter, registers, stack, and state

POSIX Threads

  • The Pthreads function calls include:
  • Pthread_create: Creates a new thread
  • Pthread_exit: Terminates the calling thread
  • Pthread_join: Waits for a specific thread to exit
  • Pthread_yield: Releases the CPU for another thread
  • Pthread_attr_init: Creates/initializes a thread's attribute structure
  • Pthread_attr_destroy: Removes a thread's attribute structure

Race Conditions

  • Competition for shared memory leads to race conditions

Critical Regions

  • To avoid race conditions:
    • No two processes can be inside their critical regions simultaneously
    • No assumptions can be made about CPU counts or speeds
    • No process outside its critical region can block other processes
    • No process should wait forever to enter its critical region
  • Mutual exclusion makes use of critical regions

Mutual Exclusion with Busy Waiting

  • Busy waiting with strict alternation can be a proposed solution to critical region problems

Producer-Consumer Problem

  • Sleep and wakeup are used in the producer-consumer problem
  • The producer generates and puts items in buffer, the consumer takes them
  • Semaphores also solve the producer-consumer problem

Semaphores

  • When using semaphores:
    • Mutex controls access to critical region
    • One counts empty buffer slots
    • One counts full buffer slots

Mutexes in Pthreads

  • Mutexes in Pthreads offers function calls such as:
    • Pthread_mutex_init: Creates a mutex
    • Pthread_mutex_destroy: Destroys an existing mutex
    • Pthread_mutex_lock: Acquires a lock or block
    • Pthread_mutex_trylock: Acquires a lock or fail
    • Pthread_mutex_unlock: Releases a lock
  • Pthreads calls relating to condition variables include:
    • Pthread_cond_init: Creates a condition variable
    • Pthread_cond_destroy: Destroys a condition variable
    • Pthread_cond_wait: Blocks waiting for a signal
    • Pthread_cond_signal: Signals another thread and wakes it
    • Pthread_cond_broadcast: Signals multiple threads and wakes them all
  • Threads can be used to solve the producer-consumer problem

Process Behavior

  • CPU usage alternates with I/O waiting periods
  • A CPU-bound process mainly uses the CPU with few I/O waits
  • An I/O-bound process spends a lot of time waiting for I/O

Scheduling Algorithm Categories

  • Batch
  • Interactive
  • Real time

Scheduling Algorithm Goals

  • All systems have to be fair, enforce policy, and keep the system busy
  • Batch systems maximize throughput, minimize turnaround time, and keep the CPU busy
  • Interactive systems have to respond quickly, and meed users expectations
  • Real-time systems avoid losing data by meeting deadlines and avoid degradation by being predictable
  • Average turnaround time vs Average wait time

Scheduling in Batch Systems

  • Scheduling algorithms for batch systems:
    • First-Come First-Served
    • Shortest Job First
    • Shortest Remaining Time Next
  • Preemptive vs. Non-Preemptive
    • Preemptive = Interrupting
    • Non-Preemptive = Not interrupting
    • Execution of a process only stops when completed

Shortest Job First

  • The shortest jobs are scheduled first

Scheduling in Interactive Systems

  • Interactive systems uses the following scheduling mechanisms:
    • Round-Robin Scheduling
    • Priority Scheduling
    • Multiple Queues
    • Shortest Process Next
    • Guaranteed Scheduling
    • Lottery Scheduling
    • Fair-Share Scheduling
  • Preemptive or Non-Preemptive

Round-Robin Scheduling

  • Each process is assigned a time interval, called its quantum, during which it is allowed to run
  • If the process is still running at the end of the quantum, the CPU is preempted and given to another process

Priority Scheduling

  • Each process is assigned a priority, and the runnable process with the highest priority is allowed to run

Scheduling in Real-Time Systems

  • Time is essential
  • Scheduling categories include:
    • Hard real time
    • Soft real time
    • Periodic or aperiodic m
    • Schedulable satisfies Σ≤1 i=1

Thread Scheduling

  • User-level threads and kernel picks a process
  • Kernel-level threads picks a thread

Dining Philosophers Problem

  • Illustrates the challenges of resource allocation and concurrency control in operating systems
  • Code given shows a faulty and correct implementation of solution

Readers and Writers Problem

  • Models concurrent access to a database
  • Shows code implementation

Studying That Suits You

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

Quiz Team

Related Documents

More Like This

Process States and Transitions Quiz
25 questions
Process States and Transitions Quiz
3 questions
Process States Quiz
5 questions

Process States Quiz

IntegralPetra avatar
IntegralPetra
Use Quizgecko on...
Browser
Browser