Podcast
Questions and Answers
Which of the following is the most accurate definition of a process?
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.
A program is a dynamic execution of a process.
False (B)
What is the purpose of the process identifier (PID)?
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.
A process may create several new processes via a ______ system call.
Match the following process termination conditions with their types:
Match the following process termination conditions with their types:
Which section of a process's memory contains global variables?
Which section of a process's memory contains global variables?
When a process is in the 'Blocked' state, it is actively using the CPU.
When a process is in the 'Blocked' state, it is actively using the CPU.
What data structure is used by the OS to maintain information about each process?
What data structure is used by the OS to maintain information about each process?
The act of stopping one process and starting another is known as _______.
The act of stopping one process and starting another is known as _______.
Which of the following is NOT a typical cause for process creation?
Which of the following is NOT a typical cause for process creation?
Context switching is a purely productive activity for the system.
Context switching is a purely productive activity for the system.
Name three pieces of information stored within a Process Control Block (PCB).
Name three pieces of information stored within a Process Control Block (PCB).
In UNIX, the system call used to terminate another process is called ______.
In UNIX, the system call used to terminate another process is called ______.
Which process state indicates that a process is waiting to be assigned to a processor?
Which process state indicates that a process is waiting to be assigned to a processor?
A parent process cannot monitor the execution of its child processes.
A parent process cannot monitor the execution of its child processes.
What is the difference between a program and a process?
What is the difference between a program and a process?
In process creation, the duplicate of the parent process is called the _______.
In process creation, the duplicate of the parent process is called the _______.
Which of the following is NOT a reason for process termination?
Which of the following is NOT a reason for process termination?
The 'Heap' section of a process is used for storing temporary data like function parameters.
The 'Heap' section of a process is used for storing temporary data like function parameters.
Briefly describe what happens during a context switch.
Briefly describe what happens during a context switch.
Processes that interact with users are known as ______ processes.
Processes that interact with users are known as ______ processes.
Which of the following actions would cause a transition from the 'Blocked' state to the 'Ready' state?
Which of the following actions would cause a transition from the 'Blocked' state to the 'Ready' state?
A process can only be in one state at a time.
A process can only be in one state at a time.
What is the main function of the 'Text' section in a process's memory layout?
What is the main function of the 'Text' section in a process's memory layout?
Processes that are not associated with particular users but have some specific function are called ______ processes.
Processes that are not associated with particular users but have some specific function are called ______ processes.
Which of the following is the most accurate description of a thread?
Which of the following is the most accurate description of a thread?
Threads within the same process have independent address spaces.
Threads within the same process have independent address spaces.
What is multithreading?
What is multithreading?
A thread has a program ________ that keeps track of which instruction to execute next.
A thread has a program ________ that keeps track of which instruction to execute next.
Which of the following resources is typically shared by all threads within a process?
Which of the following resources is typically shared by all threads within a process?
If one thread in a process is blocked, the entire process is blocked.
If one thread in a process is blocked, the entire process is blocked.
List two advantages of using threads.
List two advantages of using threads.
______ is an API used to create and manage threads
______ is an API used to create and manage threads
Which of the following is NOT a basic thread library?
Which of the following is NOT a basic thread library?
Implementing threads in user space makes the kernel aware of the existence of threads.
Implementing threads in user space makes the kernel aware of the existence of threads.
What is the main advantage of implementing threads in kernel space?
What is the main advantage of implementing threads in kernel space?
______ occurs when a system can perform more than one task simultaneously.
______ occurs when a system can perform more than one task simultaneously.
According to Amdahl's Law, what factor has a disproportionate effect on performance gained by adding additional cores?
According to Amdahl's Law, what factor has a disproportionate effect on performance gained by adding additional cores?
Data parallelism involves dividing tasks among multiple cores, whereas task parallelism divides data among multiple cores.
Data parallelism involves dividing tasks among multiple cores, whereas task parallelism divides data among multiple cores.
Explain the difference between concurrency and parallelism.
Explain the difference between concurrency and parallelism.
Flashcards
What is a process?
What is a process?
A program in execution; an activity with a program, input, output, and state.
Process Control Block (PCB)
Process Control Block (PCB)
A data structure maintained by the OS for every process, storing information about it.
Context Switching
Context Switching
Stopping one process and starting another, saving/restoring states.
Three Process States
Three Process States
Signup and view all the flashcards
Process Stack
Process Stack
Signup and view all the flashcards
Process Heap
Process Heap
Signup and view all the flashcards
What is a Thread?
What is a Thread?
Signup and view all the flashcards
Threads vs Processes: Independence
Threads vs Processes: Independence
Signup and view all the flashcards
Multithreading
Multithreading
Signup and view all the flashcards
Two ways to implement threads
Two ways to implement threads
Signup and view all the flashcards
Benefits of Multithreading
Benefits of Multithreading
Signup and view all the flashcards
Data parallelism
Data parallelism
Signup and view all the flashcards
Task parallelism
Task parallelism
Signup and view all the flashcards
Thread library
Thread library
Signup and view all the flashcards
What is context switching?
What is context switching?
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.