0% found this document useful (0 votes)
5 views32 pages

add-ch3

A process is a program in execution, consisting of program code, current activity, and various states such as running, waiting, and terminated. Processes are created and terminated through system calls, with a parent-child relationship allowing for hierarchical structures. Process scheduling is crucial for optimizing CPU utilization and system performance, utilizing various algorithms to manage multiple processes effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views32 pages

add-ch3

A process is a program in execution, consisting of program code, current activity, and various states such as running, waiting, and terminated. Processes are created and terminated through system calls, with a parent-child relationship allowing for hierarchical structures. Process scheduling is crucial for optimizing CPU utilization and system performance, utilizing various algorithms to manage multiple processes effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Process Concept

A process is a program in execution.


• Program: A set of instructions stored in a file (e.g.,
.exe, .sh, or .py).
• Execution: When a program is loaded into memory
and actively running on the CPU, it becomes a
process.
• Every task executed on a system is carried out by
processes, whether it's running an application like a
text editor or a background system service.
A process consists of:
• Program Code: The set of instructions to be executed.
• Current Activity: The current state of the process,
including variables, program counter, and registers.
• Process State: Processes have states such as
"running", "waiting", "ready", or "terminated".
All tasks executed on a system are carried out through processes

• Examples of Processes:
• When you launch a web browser, the system creates a
process to execute the browser's code.
• Running a terminal command (e.g., ls or dir) starts a new
process to execute that command.
• System processes like System Idle Process or explorer.exe in
Windows ensure smooth background operations like
managing file systems or handling user interfaces.
Example:
Features of Processes

Process in OS

1. Scheduling
3. Process State

2. Creation and Termination


1. Scheduling
• Process scheduling is the method by which an
operating system decides the order in which
processes are executed by the CPU. The goal is to
optimize CPU utilization, throughput, and response
time.
• CPU Resources: The operating system allocates CPU
time to processes to ensure that all running processes
have a fair chance to execute.
Scheduling Algorithms
• First-Come, First-Served (FCFS) Scheduling
• Shortest-Job-Next (SJN) Scheduling
• Priority Scheduling
• Shortest Remaining Time
• Round Robin(RR) Scheduling
• Multiple-Level Queues Scheduling
•What do you think about the importance of
process scheduling in a multitasking
operating system?
•How does it affect system performance?
Illustration
• In a multi-user operating system, when multiple users
run applications simultaneously, the OS uses
scheduling algorithms to switch between these
applications, giving each user a responsive experience.
For instance, if one user is running a web browser and
another is editing a document, the OS will alternate
between processes to manage resource allocation
effectively
2. Creation and Termination
• Process Creation:
Processes are created through system calls, which
are special functions provided by the operating
system. An example in UNIX/Linux is the fork()
system call.
Forking: When a process calls fork(), it creates a
child process that is an exact copy of the parent
process, including its code, data, and execution state.
Example fork() in Unix/Linux
If a fork() call is successful :
• The OS will create two identical copies of the
address space for parent and child processes.
Therefore, the address spaces of the parent and
child processes are different.
• The new child process's process ID, or PID, is
returned to the parent process. If something
goes wrong, the parent process returns -1.
Zero is returned to the new child process. (In the
case of failure, the child process is not created).

image
Example fork() in Unix/Linux

Parent process: PID = 4521, Child PID = 4522


Child process: PID = 4522, Parent PID = 4521
2. Creation and Termination (cont.)
• Parent-Child Relationship

The operating system maintains a hierarchical structure of


processes where:
- The parent process can create multiple child processes.
- Each child process can further create its own child
processes, forming a tree-like structure.
Parent-Child Relationship Examples
Terminal/Command Line and Shell Process (Unix/Linux):
When you open a terminal (like bash or zsh), a shell process is created. (parent
process).
When you type a command (e.g., ls, grep, etc.), the shell creates a child process
to run that command.
The parent process (shell) waits for the child process to finish executing the
command and then returns to allow you to input more commands.
Parent-Child Relationship Examples
Compiling and Running a Program:
When you compile a program using gcc or clang in Linux (parent), the terminal's
shell creates a child process to run the compiler (child).
After the program is compiled, you run the resulting executable, which
becomes another child process of the shell.

Parent Process: The shell (bash or zsh).


Child Processes: One for compiling the code and another for running the
compiled executable.
2. Creation and Termination (cont.)
• Process Termination:
A process can terminate in two ways:
• Voluntary Termination: This occurs when a process
completes its task and exits normally (e.g., a user saves
and closes a document in a text editor).
• Involuntary Termination: This can happen due to errors
(e.g., segmentation faults) or if the operating system
forcibly kills a process to reclaim resources.
3. Process States
A process can exist in various states during its lifecycle.
• Key States:
• New: The process is being created and is not yet ready for execution.
• Running: The process is currently being executed on the CPU.
• Waiting: The process is not currently executing because it is waiting for
an event to occur (e.g., waiting for I/O completion).
• Ready: The process is waiting for CPU time and is ready to execute.
• Terminated: The process has completed execution and is no longer in
the system.
Process Control Block (PCB)
Process Control Block (PCB)
1. Process State
• The state of a process indicates its current status in the execution lifecycle.
• Possible States:
• Running: The process is currently being executed by the CPU.
• Waiting: The process is waiting for some event (such as I/O completion) to
occur before it can proceed.
• Ready: The process is ready to run and waiting for CPU time.
• New: The process is in the creation stage and has not yet been loaded into
memory.
• Terminated: The process has finished execution and is being removed from
memory.
Process Control Block (PCB)
2. Program Counter
• The program counter (PC) is a register that holds the memory address
of the next instruction that will be executed for the process.
• Functionality:
• It ensures the CPU knows where to resume
execution after an interruption or when switching
contexts between processes.
• After executing an instruction, the PC is updated to
point to the next instruction in sequence.
• Example: If the current instruction is at memory
address 0x0040, once executed, the program counter
will increment to point to the next instruction's
address, say 0x0044.
Process Control Block (PCB)
3. CPU Registers
• CPU registers are small storage locations within the CPU that
temporarily hold data, instructions, and addresses that are critical to
the execution of a process.
• Registers may include general-purpose registers (for temporary data
storage), index registers (for indexed addressing), and stack pointers
(indicating the current position of the stack).
CPU Register

image
Type of CPU Register
• Types of CPU Registers*
• Program Counter (PC): The Program Counter keeps track of
the memory address of the next instruction to be fetched
and executed.
• Instruction Register (IR): The Instruction Register holds the
currently fetched instruction being executed.
• Accumulator (ACC): The Accumulator is a general-purpose
register used for arithmetic and logical operations. It stores
intermediate results during calculations.
*Depending on the CPUs architecture and design, the type and number of registers can vary.
Common types of registers found in a CPU may include:
Type of CPU Register
• Types of CPU Registers
• General-Purpose Registers (R0, R1, R2…): These registers are used to store data during calculations
and data manipulation. They can be accessed and utilized by the programmer for various purposes.
• Address Registers (AR): Address Registers store memory addresses for data access or for transferring
data between different memory locations.
• Stack Pointer (SP): The Stack Pointer points to the top of the stack, which is a region of memory used
for temporary storage during function calls and other operations.
• Data Registers (DR): These registers store data fetched from memory or obtained from input/output
operations.
• Status Register/Flags Register (SR): The Status Register or Flags Register contains individual bits that
indicate the outcome of operations, such as carry, overflow, zero result, and others. These flags help in
making decisions and controlling program flow based on the results of previous operations.
• Control Registers (CR): Control Registers manage various control settings and parameters related to
the CPU's operation, such as interrupt handling, memory management, and system configuration.

image
Process Control Block (PCB)
4. CPU Scheduling Information
• This section of the PCB contains data relevant to how
the process is scheduled for execution by the CPU.
• Components:
• Priority: A numerical value indicating the process's
priority level. Higher values may indicate higher priority.
• Scheduling Queue Pointers: Pointers to other PCBs in the
scheduling queues (such as ready, waiting, etc.) that help
the scheduler manage the process's state efficiently.
Process Control Block (PCB)
5. Memory-Management Information
• It holds information related to memory allocation for the process.
• Contents:
• Base Register: Indicates the starting physical address where the
process's memory segment is located.
• Limit Register: Specifies the size of the process's memory segment
to prevent it from accessing memory allocated to other processes.
• Page Tables: If the system uses virtual memory, this information
can include page tables that map virtual addresses to physical
addresses.
Process Control Block (PCB)
6. Accounting Information
• This contains various statistics about the process's resource usage.
• Contents:
• CPU Used: The total CPU time consumed by the process.
• Clock Time Elapsed: The real time that has passed since the process
started.
• Time Limits: Maximum allowed execution time for the process, which
can be enforced by the operating syste
Process Control Block (PCB)
7. I/O Status Information
• This section contains information about I/O devices allocated to the
process and its interactions with files.
• Contents:
• Allocated I/O Devices: A list of devices (e.g., printers, disk drives)
currently assigned to the process.
• List of Open Files: A list of files that the process is currently using,
along with their file descriptors.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy