Processes and Threads

Processes

A process is a running program, including the current value of the program counter (PC), registers, and variables. Processes are managed by the operating system and consist of:

  • Instructions to be executed by the microprocessor.
  • Implementation status (register values).
  • Working memory (reserved memory and its contents).
  • Information for operating system scheduling.

Process States

Running: The process is being executed on the CPU. Only one process can be in this state on a uniprocessor system.

Ready: The process is able to run but is waiting for its turn on the CPU.

Blocked: The process is waiting for an event, such as I/O completion. This state is also called suspended or on hold.

Context Switching and Process Creation

A context switch stops the execution of one thread (or process) to allow another to run. A parent process can create child processes through system calls. These children can, in turn, create other processes.

Threads

A thread allows an application to perform multiple tasks concurrently. Threads share resources like memory, open files, and authentication status, simplifying application design. Threads and their shared resources together constitute a process.

Because threads share resources, any thread can modify them. When one thread modifies data in memory, other threads immediately access the modified data.

Thread Benefits and States

Benefits: Threads are faster to create and terminate than processes.

States: Creation, lock, unlock, completion (release of context and resources).

Asynchronous Operations

Each operation has its own time.

Multiprogramming and Multiprocessing

Multiprogramming: Managing multiple processes within a single-processor system.

Multiprocessing: Managing multiple processes within a multiprocessor system.

Concurrency Issues

Concurrency involves inter-process communication, resource sharing and competition, process synchronization, and processor time allocation. These issues arise in multiprocessor, distributed, and even single-processor multiprogramming systems.

Micronuclei

A micronucleus is a small OS core containing essential functions. Benefits include uniform interfaces, extensibility, flexibility, portability, reliability, distributed system support, and object-oriented design.

Critical Region

A critical region is when a process modifies shared data, and no other process can access it until the modification is complete.

Deadlocks, Race Conditions, and Starvation

Deadlock: Two or more processes are blocked indefinitely, waiting for each other to release resources.

Race Condition: The output of a process depends on the unpredictable order of events.

Starvation: A process is perpetually denied necessary resources.

Inter-process Communication

Processes communicate, compete for, and share resources.

Interrupts

Types of interrupts include clock, I/O, software, user, and hardware interrupts.

Zombie Processes

A zombie process is a terminated process whose resources have not yet been released.

Deadlock Conditions

Mutual Exclusion: A resource can only be held by one process at a time.

Hold and Wait: A process holding resources can request additional resources.

No Preemption: Resources cannot be forcibly taken from a process.

Circular Wait: A cycle of processes exists where each process is waiting for a resource held by the next process in the cycle.

Deadlock Avoidance

Deadlock avoidance involves negating one or more of the deadlock conditions.