Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Introduction:

Understanding Processes in Computer Systems

Evolution of Computing Paradigms

In the early days of computing, systems were capable of executing only one program
at a time. This program wielded complete control over the system and could access all
its resources without restriction. However, this approach hindered system efficiency and
capability.

Introduction of Processes

Modern computer systems have evolved to support concurrent execution of multiple


programs. To manage this, the concept of a process emerged.

• Process Definition: A process is essentially a program in execution, representing the


unit of work in a contemporary time-sharing system.

Purpose of Processes

• Enhanced Control: Processes provide firmer control and compartmentalization of


programs, ensuring isolation and effective management of individual program
execution.
• Resource Management: Processes facilitate efficient resource allocation among
multiple programs, thereby enhancing system performance.

Components of a System

A modern computer system comprises distinct types of processes:

1. Operating System Processes: These processes execute system code and handle critical
system tasks.
2. User Processes: These processes execute user code and represent tasks initiated by
users.

Concurrent Execution
• Multiplexing CPU: In a multitasking environment, multiple processes can execute
concurrently. The CPU switches between processes, a technique known as CPU
multiplexing, which boosts overall productivity.

Role of Operating System

While the primary responsibility of the operating system is executing user programs, it
also performs various system tasks. These tasks are executed as separate operating
system processes, ensuring efficient management outside the kernel.

Conclusion

Understanding processes is crucial for grasping the operation of modern computer


systems. Subsequent chapters will delve into the intricacies of processes, elucidating
their role in system performance and management.
3.1 Process Concept
Introduction

In the realm of operating systems, understanding CPU activities is crucial.


Different systems handle these activities differently. For instance, batch
systems deal with executing jobs, while time-shared systems handle user
programs or tasks. Despite these variations, all these activities are
fundamentally similar, leading to the adoption of the term "process" to
encompass them all.

Definition of a Process

Informally, a process is a program in execution. However, it encompasses


more than just the program code. A process also includes the current activity,
represented by the program counter and the contents of the CPU registers.
Additionally, it consists of the process stack (for temporary data), the data
section (for global variables), and potentially a heap (for dynamically
allocated memory).

Transformation from Program to Process


A program is essentially a passive entity, stored as a set of instructions on
disk. In contrast, a process is an active entity, with its own program counter
and associated resources. When an executable file is loaded into memory, it
becomes a process. This loading can occur through actions such as double-
clicking an icon or entering a command on the command line.

Multiplicity of Processes

Even if multiple processes are associated with the same program, they are
considered separate execution sequences. For example, multiple users may
run different instances of the same program simultaneously. Each of these
instances constitutes a separate process, with variations in data, heap, and
stack sections.

Process as an Execution Environment

A process can itself serve as an execution environment for other code. For
instance, the Java Virtual Machine (JVM) executes as a process, interpreting
and executing Java code. This setup allows for the execution of Java programs
within the JVM environment.

Process State

As a process executes, it transitions through different states:

• New: The process is being created.


• Running: Instructions are being executed.
• Waiting: The process is awaiting an event (e.g., I/O completion).
• Ready: The process is ready to be assigned to a processor.
• Terminated: The process has finished execution.

These states may vary across operating systems, but the underlying concepts
remain consistent.

Process Control Block (PCB)


Each process is represented in the operating system by a Process Control
Block (PCB), which contains various pieces of information associated with the
process:

• Process State
• Program Counter
• CPU Registers
• CPU-Scheduling Information
• Memory-Management Information
• Accounting Information
• I/O Status Information

The PCB serves as a repository for information that may vary from process to
process.

Threads

Modern operating systems extend the process concept to allow for multiple
threads of execution within a single process. This feature enables a process
to perform more than one task simultaneously, which is particularly
advantageous on multicore systems. The PCB is expanded to include
information for each thread, and other system changes are made to support
threads.

Representation in Linux

In the Linux operating system, the PCB is represented by the task_struct


structure, which contains all necessary information for representing a process.
This includes the process state, scheduling and memory-management
information, lists of open files and children processes, among others.

Understanding processes and their management is fundamental to operating


system design and functionality.

3.2 Process Scheduling


Multiprogramming Objective:
• Objective: Ensure continuous CPU utilization by having at least one process
running at all times.
• Maximizing CPU Utilization: By keeping the CPU busy with executing
processes, multiprogramming aims to make the most efficient use of available
CPU resources.

Time Sharing Objective:

• Objective: Enable users to interact with multiple programs concurrently by


rapidly switching the CPU among processes.
• User Interaction: Time sharing facilitates user interaction with programs by
swiftly alternating between executing processes, allowing users to perceive
simultaneous operation.

Process Scheduler
Purpose:

• CPU Allocation: Selects a process for execution on the CPU, maintaining


system efficiency and responsiveness.
• Single-Processor Systems: In systems with a single CPU, only one process
can execute at a time, necessitating efficient scheduling to manage multiple
processes.

Scheduling Queues
Types:

• Job Queue: Contains all processes in the system, awaiting execution.


• Ready Queue: Stores processes in main memory ready to execute.
• Device Queues: Holds processes waiting for specific I/O devices, each device
having its own queue.

Queueing Diagram
• Representation: A visual depiction of process scheduling, illustrating the flow
of processes through various queues and resources in the system.
Process State Transition
States and Transitions:

• New Process: Enters the ready queue, awaiting execution (dispatch).


• While Executing: Processes may transition due to I/O requests, creation of
child processes, or interrupts.
• Cycle Continuation: Processes repeat this cycle until termination, after which
they are removed from all queues and resources deallocated.

Schedulers
Types:

• Long-Term Scheduler: Controls multiprogramming by selecting processes


from a pool for memory allocation.
• Short-Term Scheduler: Allocates CPU to processes from the ready queue,
executing frequently for rapid process switching.

Context Switch
Process Context:

• Components: Includes CPU registers, process state, and memory-


management information, stored in the Process Control Block (PCB).
• Context Switch: Involves saving the current process context and loading a
different process context for CPU switching.
• Overhead: Context-switch time is overhead as no useful work occurs during
switching.

Multitasking in Mobile Systems (iOS and Android)


iOS:

• Limited Multitasking: Introduced in iOS 4 for user applications, with


constraints on application types and background execution.
Android:

• No Constraints: Android allows background applications without limitations.


Background processing is facilitated using services, ensuring continuous
operation even when the application is suspended.

Understanding these concepts is crucial for optimizing CPU utilization and


effectively managing processes in operating systems.

3.3 Operations on Processes


Introduction

In computer systems, processes are fundamental units of execution. They can


run concurrently, and the operating system needs mechanisms to create and
terminate them efficiently. This section explores the intricacies of process
creation and termination on various operating systems, shedding light on
their underlying mechanisms.

Process Creation

• Parent-Child Relationship: When a process creates another process, it


establishes a parent-child relationship. The parent process initiates the
creation, and the newly created process becomes its child.
• Process Identification: Operating systems assign each process a unique
identifier, known as the process ID (pid). This identifier allows the OS to
manage and track processes effectively.
• Process Tree: Processes in many operating systems are organized in a
hierarchical structure known as a process tree. The root of this tree is typically
the initial process spawned during system boot, such as the init process in
UNIX-like systems.

Process Creation Mechanisms


• Resource Allocation: When a process creates a child, it may allocate
resources to it directly or restrict its access to a subset of its own resources.
This ensures efficient utilization of system resources.
• Initialization Data: Parent processes can pass initialization data to their
children, enabling them to perform specific tasks or access required resources
upon creation.
• Execution Possibilities: Upon creation, a child process may either execute
concurrently with its parent or wait until the parent or some other children
have terminated, depending on the system's design and requirements.

Process Creation in UNIX and Linux

• fork() System Call: In UNIX-like systems, the fork() system call is used to
create a new process by duplicating the address space of the parent. This
allows both the parent and child processes to continue execution
independently.
• exec() System Call: After forking, a process may use the exec() system call to
replace its memory space with a new program. This mechanism enables
seamless communication between parent and child processes before they
diverge.

Process Creation in Windows

• CreateProcess() Function: Windows systems use the CreateProcess() function


to create new processes. Unlike fork(), CreateProcess() requires specifying the
program to be loaded into the child process's address space at creation.

Process Termination

• Normal Termination: A process terminates when it finishes executing its


tasks and invokes the exit() system call. At this point, the operating system
deallocates all resources associated with the process.
• Other Termination Scenarios: Processes can also be terminated by other
processes via appropriate system calls, typically restricted to the parent
process terminating its children.
• Orphan Processes: In UNIX-like systems, orphan processes—those left
without a parent—are reassigned to the init process. This ensures proper
resource deallocation and prevents resource leakage.

Understanding the nuances of process creation and termination is essential for


efficient resource management and system stability in operating systems.

Queued and Nonqueued Messages:


Introduction

In Windows programming, messages play a crucial role in communication


between the operating system and applications. Messages can be categorized
into two types: queued and nonqueued.

Message Handling Mechanism

- **Message Loop**: Windows programs utilize a message loop to retrieve


and process messages.

- **Message Queue**: Messages are stored in a program's message queue,


retrieved using `GetMessage`, and dispatched to the window procedure via
`DispatchMessage`.

Queued Messages

- **Definition**: Messages placed in the program's message queue by


Windows.

- **Handling**: Retrieved and dispatched in the program's message loop.

- **Examples**: User input (keystrokes, mouse movement), timer events,


repaint requests, quit signals.
Nonqueued Messages

- **Definition**: Messages sent directly to the window procedure by


Windows.

- **Handling**: The window procedure receives these messages directly.

- **Examples**: Result from certain Windows function calls (e.g.,


`CreateWindow`, `ShowWindow`, `UpdateWindow`).

Message Processing

- **Orderly and Synchronized**: Messages are processed in an orderly and


synchronized manner within the window procedure.

- **Concurrency**: While a message is being processed, the program is not


interrupted by another message.

- **Thread-Specific Handling**: Each thread's message queue handles


messages only for the windows whose procedures are executed in that thread.

Reentrancy and State Management

- **Reentrant Window Procedures**: Window procedures must be reentrant


to handle potential nested message processing.

- **Variable State**: Window procedures must manage variable state


carefully, considering the possibility of nested message processing.

- **Compiler Optimization**: Certain forms of compiler optimization may


need to be disabled to ensure proper variable management in window
procedures.

Information Retention
- **Static Variables**: Information obtained in one message and required for
processing subsequent messages is typically stored in static variables within
the window procedure.

- **Global Variables**: Alternatively, information may be stored in global


variables for broader accessibility.

Conclusion

Understanding the intricacies of queued and nonqueued messages, along with


the management of variable state and reentrancy, is essential for effective
Windows programming. As window procedures are expanded to handle more
messages in later chapters, developers gain a deeper understanding of
message processing and management.

You might also like