Unit-2: Concurrent Processes
Assignment-1
Q.1- Explain Principles of concurrency.
Answer:
Concurrency is the ability of a system to execute multiple tasks simultaneously, improving
performance and responsiveness. Key principles include:
- Process synchronization: Ensures orderly access to shared resources.
- Mutual exclusion: Only one process accesses a critical section at a time.
- Deadlock prevention: Ensures processes do not block each other permanently.
- Starvation freedom: Guarantees every process gets a fair chance.
Q.2- What is producer-consumer problem?
Answer:
The producer-consumer problem describes two processes: the producer, which generates data, and
the consumer, which uses it. They share a common buffer. Proper synchronization ensures the
producer does not add data into a full buffer and the consumer does not remove data from an empty
buffer.
Q.3- What is critical section? Explain Algorithm to solve it.
Answer:
A critical section is a part of a program that accesses shared resources and must not be executed
by more than one process at a time.
Algorithm: Peterson's Algorithm is a classical solution:
- Uses two variables: flag[i] and turn.
- Ensures mutual exclusion, progress, and bounded waiting.
Q.4- What is Dekker Solution?
Answer:
Dekker's Algorithm is one of the first known solutions to the mutual exclusion problem in concurrent
programming. It uses busy waiting and shared variables to alternate access to the critical section
between two processes.
Q.5- What is Paterson's Algorithm and its solution.
Answer:
Peterson's Algorithm solves the critical section problem for two processes using two shared
variables:
- flag[i]: indicates process i wants to enter the critical section.
- turn: indicates whose turn it is.
It ensures mutual exclusion and avoids race conditions.
Assignment-2
Q.1- Write short note on semaphores.
Answer:
Semaphores are synchronization tools used to manage access to shared resources. There are two
types:
- Binary semaphore: Acts like a mutex (0 or 1).
- Counting semaphore: Can take non-negative integer values.
They use wait() and signal() operations to control access.
Q.2- What is race condition?
Answer:
A race condition occurs when multiple processes access and manipulate shared data concurrently,
and the final outcome depends on the order of execution. It can lead to unpredictable and incorrect
behavior.
Q.3- Explain Dining Philosopher Problem for synchronization.
Answer:
The Dining Philosopher Problem models a situation where philosophers share chopsticks. Each
needs two to eat but only one is available at a time. The problem illustrates deadlock and resource
starvation issues, solved using semaphores or monitors.
Q.4- What is Inter Process Communication?
Answer:
Inter Process Communication (IPC) allows processes to communicate and synchronize with each
other. Methods include:
- Shared memory
- Message passing
- Pipes and sockets
IPC ensures data consistency and coordination between processes.
Q.5- What is a process? How is it generated?
Answer:
A process is an instance of a program in execution. It includes the program code, current activity,
and memory. Processes are created by system calls like fork() in UNIX. The operating system
manages their creation, execution, and termination.