Process | Multi-Processing | Thread | Multi-Threading Flashcards
What is a Process?
A Process is an instance of a program in execution. It has its own memory space, resources, and state. Each process is independent of other processes.
What are the components of a Process?
A Process consists of: 1) Code (text section), 2) Data (variables), 3) Heap (dynamic memory), 4) Stack (function calls and local variables), and 5) Process Control Block (PCB).
What is a Process Control Block (PCB)?
The PCB is a data structure used by the OS to store information about a process, such as Process ID (PID), program counter, CPU registers, memory limits, and process state.
What are the states of a Process?
The states of a Process are: 1) New, 2) Ready, 3) Running, 4) Waiting (or Blocked), and 5) Terminated.
What is Context Switching?
Context Switching is the process of saving the state of a running process and loading the state of another process so that the CPU can execute it. It is essential for multitasking.
What is the difference between a Process and a Program?
A Program is a static set of instructions stored on disk, while a Process is a dynamic instance of a program being executed in memory.
What is a Thread?
A Thread is the smallest unit of execution within a process. It shares the same memory space and resources as other threads in the same process but has its own stack and program counter.
What is the difference between a Process and a Thread?
A Process is independent and has its own memory space, while a Thread is a lightweight unit of execution within a process and shares memory with other threads in the same process.
What are the advantages of using Threads?
Advantages of Threads include: 1) Faster creation and context switching, 2) Efficient communication (shared memory), 3) Better resource utilization, and 4) Improved responsiveness in applications.
What are the disadvantages of using Threads?
Disadvantages of Threads include: 1) Complexity in synchronization, 2) Risk of race conditions, 3) Debugging difficulties, and 4) Potential for deadlocks.
What is Multithreading?
Multithreading is the ability of a CPU to execute multiple threads concurrently within a single process. It allows parallel execution of tasks and improves application performance.
What are the types of Multithreading?
The types of Multithreading are: 1) User-Level Threads (managed by user libraries) and 2) Kernel-Level Threads (managed by the OS).
What is the difference between User-Level Threads and Kernel-Level Threads?
User-Level Threads are managed by user libraries and are faster to create, but they cannot leverage multiple CPUs. Kernel-Level Threads are managed by the OS and can run on multiple CPUs but have higher overhead.
What is a Race Condition?
A Race Condition occurs when two or more threads access shared data simultaneously, leading to unpredictable results due to improper synchronization.
What is Synchronization in Multithreading?
Synchronization ensures that only one thread can access a shared resource at a time. It is achieved using tools like mutexes, semaphores, and monitors.
What is a Mutex?
A Mutex (Mutual Exclusion) is a synchronization primitive that ensures only one thread can access a shared resource at a time. It prevents race conditions.
What is a Semaphore?
A Semaphore is a synchronization tool that controls access to shared resources using a counter. It can allow multiple threads to access a resource up to a specified limit.
What is a Deadlock?
A Deadlock occurs when two or more threads are blocked forever, waiting for each other to release resources. The four conditions for deadlock are: 1) Mutual Exclusion, 2) Hold and Wait, 3) No Preemption, and 4) Circular Wait.
How can Deadlocks be prevented?
Deadlocks can be prevented by breaking one of the four conditions: 1) Avoid Mutual Exclusion, 2) Eliminate Hold and Wait, 3) Allow Preemption, or 4) Break Circular Wait.
What is the Banker’s Algorithm?
The Banker’s Algorithm is a deadlock avoidance algorithm that checks if allocating resources to a process will leave the system in a safe state (where all processes can complete without causing a deadlock).
What is Multiprocessing?
Multiprocessing refers to the use of multiple CPUs or cores within a single computer system to execute multiple processes simultaneously. It enables true parallel execution.
What is the difference between Multiprocessing and Multithreading?
Multiprocessing uses multiple CPUs/cores to execute processes independently, while Multithreading uses a single CPU/core to execute multiple threads within a process concurrently.
What are the advantages of Multiprocessing?
Advantages of Multiprocessing include: 1) High performance, 2) Fault tolerance (if one CPU fails, others continue), and 3) Scalability (more CPUs can be added).
What are the disadvantages of Multiprocessing?
Disadvantages of Multiprocessing include: 1) High cost, 2) Complexity in managing shared resources, and 3) Increased power consumption.