0% found this document useful (0 votes)
14 views

Process

A process is an executing program and the basic unit of resource allocation in an operating system, transitioning through five states: New, Ready, Running, Waiting, and Terminated. Each process is managed through a Process Control Block (PCB), which contains essential information like Process ID, state, program counter, and memory management details. Threads, as lightweight processes, enhance efficiency and performance by allowing concurrent execution and resource sharing within a program.

Uploaded by

wahabullah11302
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Process

A process is an executing program and the basic unit of resource allocation in an operating system, transitioning through five states: New, Ready, Running, Waiting, and Terminated. Each process is managed through a Process Control Block (PCB), which contains essential information like Process ID, state, program counter, and memory management details. Threads, as lightweight processes, enhance efficiency and performance by allowing concurrent execution and resource sharing within a program.

Uploaded by

wahabullah11302
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Process

A process is a program in execution. It is the basic unit of resource allocation in an


operating system. A process has a starting and end point. It must execute and progress
sequentially. A process is controlled and scheduled by operating system.
A program is not process by default. A program is a passive entity, i.e. a file containing a
list of instructions stored on disk (secondary memory) (often called an executable file).
A program becomes a process when an executable file is loaded into main memory and
when its PCB is created.
A process on the other hand is an Active Entity, which require resources like main
memory, CPU time, registers, system buses etc.

A Process consists of following sections:


 Text section: Also known as Program Code.
 Stack: Which contains the temporary data (Function Parameters, return
addresses and local variables).
 Data Section: Containing global variables.
 Heap: Which is memory dynamically allocated during process runtime.

Process States (5 States)


A process in an operating system can exist in one of five distinct states. These states
represent the current status of the process as it progresses from creation to
termination.

1. New:
Definition: The process is being created.
Details: This is the initial state when a process is first started. It is being prepared for
execution.
2. Ready:
Definition: The process is waiting to be assigned to a processor.
Details: The process has all the resources it needs to run, except for the CPU. It is in
the queue, waiting for its turn to execute.

3. Running:
Definition: The process is currently being executed by the processor.
Details: The CPU is actively executing the instructions of the process. Only one
process can be in the running state on a single processor system at any given time.

4. Waiting (Blocked):
Definition: The process is waiting for some event to occur (such as I/O completion or
a signal).
Details: The process cannot continue until the event it is waiting for happens. Once
the event occurs, the process may move back to the ready state.
5. Terminated:
Definition: The process has finished execution.
Details: The process has completed its execution and is no longer active. It will be
removed from memory and its resources will be reclaimed by the operating system.
Process Structure

A process in an operating system is a structured entity that contains various


components needed for its execution and management. These components are
organized into a process control block (PCB), which the operating system uses to
manage and track the process. Here is a detailed overview of the main components of a
process structure:

1) Process ID (PID):
 Definition: A unique identifier assigned to each process.
 Details: The PID is used by the operating system to keep track of each process. It
ensures that each process can be individually referenced.

2) Program Counter:
 Definition: A register that contains the address of the next instruction to be
executed.
 Details: This helps the CPU know which instruction to execute next from the
process's code.

3) Process State:
 Definition: The current status of the process.
 Details: It can be one of several states, such as new, ready, running, waiting, or
terminated.

4) CPU Registers:
 Definition: A set of registers used by the CPU to store intermediate data and
instructions.
 Details: These registers include the accumulator, index register, stack pointer,
and general‐purpose registers.
5) Memory Management Information:
 Definition: Information regarding the process's memory allocation.
 Details: This includes pointers to the process's code segment, data segment,
stack segment, and heap segment.

6) Accounting Information:
 Definition: Data related to the process’s resource usage.
 Details: This includes the amount of CPU time used, real time, job time limits, and
the process's priority.

7) I/O Status Information:


 Definition: Information about the process's input/output activities.
 Details: It includes a list of I/O devices allocated to the process, a list of open
files, and I/O requests.

8) Process Control Information:


 Definition: Information used by the operating system to manage the process.
 Details: This includes process scheduling information, pointers to the process's
parent and child processes, and inter‐process communication details.
Diagram of Process Structure:

Process ID (PID)

Program Counter

Process State

CPU Registers

Memory Management Info

Accounting Information

I/O Status Information

Process Control Information

Summary

A process structure encapsulates all necessary information to manage and execute a


process efficiently. The operating system relies on the PCB to control and schedule
processes, ensuring that each process gets the required resources and performs its tasks
correctly.

These components together allow the operating system to manage multiple processes,
switch between them efficiently, and maintain the overall system's stability and
performance.
Process Control Block (PCB) and Its Components

What is a Process Control Block (PCB)?


A Process Control Block (PCB) is a critical data structure used by operating systems to
manage processes. It contains essential information about the process, allowing the
operating system to control and manage its execution effectively.

Components of a PCB:

1) Process ID (PID)
 Description: A unique identifier assigned to each process.
 Purpose: Helps the operating system distinguish between
different processes.

2) Process State
 Description: Indicates the current state of the process (e.g.,
ready, running, waiting).
 Purpose: Tracks the status of the process for scheduling.

3) Program Counter
 Description: Contains the address of the next instruction to be executed.
 Purpose: Ensures the process continues execution from the correct point.

4) CPU Registers
 Description: Stores the contents of the CPU registers when the process is not
running.
 Purpose: Maintains the CPU's state so the process can resume correctly.
5) Memory Management Information
 Description: Information about the process's memory allocation (e.g., page
tables, segment tables).
 Purpose: Manages the process's memory requirements and ensures proper
memory usage.

6) Accounting Information
 Description: Contains data on resource usage by the process (e.g., CPU time,
memory usage).
 Purpose: Helps in resource allocation and monitoring system performance.

7) I/O Status Information


 Description: Information about the I/O devices allocated to the process and their
status.
 Purpose: Manages the process's I/O operations and tracks their status.

8) Process Privileges
 Description: Information on the permissions and access rights of the process.
 Purpose: Ensures the process operates within its allowed privileges.

Summary
The PCB is vital for the operating system's ability to manage processes effectively. It
stores all the necessary information to track, control, and execute processes, ensuring
smooth and efficient multitasking and resource management.
Operations on Processes
The operating system is responsible for providing a mechanism to create and destroy
Process dynamically.

1. Process Creation

Description: Parent process creates children processes. The


children process can also create other processes forming a tree
of processes.

Key Points:

‐ A parent process uses a system call like `fork()` to create a


child process.

‐ The child process may execute the same program as the parent or a different one.

2. Process Termination

Description: A process finishes its execution and is removed from the system.

Key Points:

‐ This can occur normally (the process completes its task) or abnormally (due to errors).

‐ The process uses a system call like `exit()` to terminate.

3. Process Suspension and Resumption

Description: Temporarily stopping a process and then restarting it.

Key Points:

‐ Suspension (or pausing) a process can free up resources or wait for certain conditions.

‐ Resumption brings the process back to execution.


4. Process Scheduling

Description: The operating system decides which process runs at a given time.

Key Points:

‐ The scheduler uses algorithms to manage process execution efficiently.

‐ This ensures fair resource distribution and maximizes CPU utilization.

5. Process Synchronization

Description: Coordination between processes to ensure they operate smoothly


together.

Key Points:

‐ Essential for processes that share resources.

‐ Prevents conflicts and ensures data consistency.

6. Inter‐process Communication (IPC)

Description: Mechanisms that allow processes to communicate and share data.

Key Points:

‐ Methods include message passing, shared memory, and pipes.

‐ Critical for processes that need to exchange information.

These operations enable the operating system to manage processes efficiently, ensuring
smooth execution and resource management.
Threads in Operating Systems

Definition:

A thread is the smallest unit of a program that can be executed independently. It is a


lightweight process within a larger process.

Explanation:
Threads allow a program to perform multiple tasks at the same time (concurrently). For
example, in a video player application:

‐ One thread might handle video playback.

‐ Another thread could manage user inputs like play, pause, or stop.

‐ A third thread could download video data from the internet.

Benefits:
1. Efficiency:

‐ Threads share the same memory space within a process, which makes them faster
and more efficient to use.

2. Improved Performance:

‐ By dividing a program into multiple threads, the program can perform multiple tasks
simultaneously, leading to better performance.

3. Resource Sharing:

‐ Threads can easily share data and resources with each other since they exist within
the same process.

Example:

Imagine a web browser:


‐ One thread could be loading a webpage.

‐ Another thread might be rendering the images.

‐ A third thread could be handling user interactions like scrolling or clicking links.

By using threads, the browser can perform these tasks simultaneously, making it faster
and more responsive to the user.

Key Points:

Thread: Smallest unit of a program that can run independently.

Concurrency: Multiple threads can run at the same time.

Resource Sharing: Threads share resources within the same process, making them
efficient.

Threads help make applications more efficient, faster, and able to handle multiple tasks
at once.

You might also like