Podcast
Questions and Answers
Which of the following is NOT one of the four principal events that cause processes to be created?
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.
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.
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.
A process transitions to the ________ state when it is unable to run until some external event occurs.
Match the process state with its description:
Match the process state with its description:
Which of the following process management fields isn't part of a typical process table entry?
Which of the following process management fields isn't part of a typical process table entry?
In the lowest level of the operating system, assembly language procedures are only used to save registers.
In the lowest level of the operating system, assembly language procedures are only used to save registers.
Explain the relationship between the degree of multiprogramming and CPU utilization.
Explain the relationship between the degree of multiprogramming and CPU utilization.
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 ________
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 ________
Match each element with its corresponding description in the context of process management within an operating system:
Match each element with its corresponding description in the context of process management within an operating system:
In a multithreaded web server, what is the primary role of the dispatcher thread?
In a multithreaded web server, what is the primary role of the dispatcher thread?
A single-threaded process can achieve parallelism.
A single-threaded process can achieve parallelism.
Describe the key difference between a thread and a process.
Describe the key difference between a thread and a process.
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.
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.
Match the item with whether it's a 'per process item' or a 'per thread item'.
Match the item with whether it's a 'per process item' or a 'per thread item'.
Which of the following Pthreads function calls is used to terminate the calling thread?
Which of the following Pthreads function calls is used to terminate the calling thread?
The pthread_join
function releases the CPU to let another thread run.
The pthread_join
function releases the CPU to let another thread run.
What is the primary purpose of the pthread_attr_init
function in Pthreads?
What is the primary purpose of the pthread_attr_init
function in Pthreads?
In Pthreads, the ________ function is used to release the CPU and allow another thread to run.
In Pthreads, the ________ function is used to release the CPU and allow another thread to run.
Match the Pthreads function with its description:
Match the Pthreads function with its description:
What is a race condition?
What is a race condition?
To avoid race conditions, it is okay to make assumptions about the speeds or the number of CPUs.
To avoid race conditions, it is okay to make assumptions about the speeds or the number of CPUs.
What are the four requirements to avoid race conditions?
What are the four requirements to avoid race conditions?
A ________ is a section of code where shared resources are accessed, and where it is crucial to avoid race conditions.
A ________ is a section of code where shared resources are accessed, and where it is crucial to avoid race conditions.
Match each of the following race condition requirements with its description:
Match each of the following race condition requirements with its description:
What is the problem with the strict alternation solution for mutual exclusion?
What is the problem with the strict alternation solution for mutual exclusion?
The 'sleep' and 'wakeup' primitives always prevent race conditions in producer-consumer problems.
The 'sleep' and 'wakeup' primitives always prevent race conditions in producer-consumer problems.
Explain how semaphores can be used to solve the producer-consumer problem.
Explain how semaphores can be used to solve the producer-consumer problem.
A semaphore is a protected variable that can signal between threads in the same process by using two atomic operations, namely ________ and ________.
A semaphore is a protected variable that can signal between threads in the same process by using two atomic operations, namely ________ and ________.
Match each term with its description in the context of process synchronization:
Match each term with its description in the context of process synchronization:
Which Pthreads call is used to acquire a lock, blocking if the mutex is already locked?
Which Pthreads call is used to acquire a lock, blocking if the mutex is already locked?
pthread_mutex_trylock
will block if the mutex is already locked.
pthread_mutex_trylock
will block if the mutex is already locked.
What is the purpose of condition variables in Pthreads?
What is the purpose of condition variables in Pthreads?
In Pthreads, the pthread_cond_wait
function allows a thread to block until ________.
In Pthreads, the pthread_cond_wait
function allows a thread to block until ________.
Match the Pthreads calls relating to condition variables with their descriptions:
Match the Pthreads calls relating to condition variables with their descriptions:
In which type of systems is throughput an important scheduling goal?
In which type of systems is throughput an important scheduling goal?
In real-time systems, predictability is more crucial than meeting deadlines.
In real-time systems, predictability is more crucial than meeting deadlines.
What is the key difference between preemptive and non-preemptive scheduling?
What is the key difference between preemptive and non-preemptive scheduling?
The shortest job first scheduling algorithm is an example of an algorithm used in ________.
The shortest job first scheduling algorithm is an example of an algorithm used in ________.
Match each scheduling type with the primary goal:
Match each scheduling type with the primary goal:
Flashcards
The Process Model
The Process Model
A model where multiple processes run seemingly simultaneously on a single CPU by rapidly switching between them.
Process Creation
Process Creation
Caused by system initialization, process creation call, user request or initiation of batch job.
Process Termination
Process Termination
Occurs due to normal exit, error exit, fatal error or being killed by another process.
Process States
Process States
Signup and view all the flashcards
Race Condition
Race Condition
Signup and view all the flashcards
Critical Region
Critical Region
Signup and view all the flashcards
Strict Alternation
Strict Alternation
Signup and view all the flashcards
Sleep and Wakeup
Sleep and Wakeup
Signup and view all the flashcards
Semaphore
Semaphore
Signup and view all the flashcards
pthread_yield
pthread_yield
Signup and view all the flashcards
pthread_create
pthread_create
Signup and view all the flashcards
Threads
Threads
Signup and view all the flashcards
pthread_mutex_init
pthread_mutex_init
Signup and view all the flashcards
pthread_mutex_lock
pthread_mutex_lock
Signup and view all the flashcards
pthread_mutex_unlock
pthread_mutex_unlock
Signup and view all the flashcards
pthread_cond_init
pthread_cond_init
Signup and view all the flashcards
pthread_cond_wait
pthread_cond_wait
Signup and view all the flashcards
pthread_cond_signal
pthread_cond_signal
Signup and view all the flashcards
pthread_cond_broadcast
pthread_cond_broadcast
Signup and view all the flashcards
Scheduling algorithm goals
Scheduling algorithm goals
Signup and view all the flashcards
First-Come First-Served
First-Come First-Served
Signup and view all the flashcards
Shortest Job First
Shortest Job First
Signup and view all the flashcards
Preemptive
Preemptive
Signup and view all the flashcards
Non-preemptive
Non-preemptive
Signup and view all the flashcards
Round-Robin Scheduling
Round-Robin Scheduling
Signup and view all the flashcards
Priority scheduling
Priority scheduling
Signup and view all the flashcards
Real-time system scheduling
Real-time system scheduling
Signup and view all the flashcards
Dining Philosophers
Dining Philosophers
Signup and view all the flashcards
Readers and Writers
Readers and Writers
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.