0% found this document useful (0 votes)
3 views8 pages

Unit 3 Processes Management and Threads

The document discusses processes in operating systems, defining a process as a running program with its own memory space and resources. It covers process scheduling, states, and the role of the Process Control Block (PCB) in managing process information. Additionally, it explains inter-process communication methods, including shared memory and message passing, highlighting their use in facilitating cooperation between processes.
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)
3 views8 pages

Unit 3 Processes Management and Threads

The document discusses processes in operating systems, defining a process as a running program with its own memory space and resources. It covers process scheduling, states, and the role of the Process Control Block (PCB) in managing process information. Additionally, it explains inter-process communication methods, including shared memory and message passing, highlighting their use in facilitating cooperation between processes.
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

Unit 3 Processes Management and Threads

Process
A process is like a running program. It's a self-contained unit of execution that has its own memory
space, resources, and a unique process ID. Think of it like a separate workspace for a program, where
it can run its code and manage its own data.

Here's a key concepts:

* Program: A set of instructions that a computer can execute.

* Process: An instance of a program that is currently running.

* Memory Space: Each process has its own dedicated area of memory where it stores its data,
instructions, and stack.

* Resources: Processes can access resources like files, network connections, and peripherals.

* PID: Every process has a unique ID that helps the operating system identify and manage it.

Processes are the fundamental units of execution in modern operating systems. They allow
multiple programs to run concurrently, sharing the computer's resources efficiently.

Process scheduling
Process scheduling in an operating system is the process of deciding which process gets to use the
CPU at any given time. The scheduler aims to ensure that all processes get a fair share of the CPU's
time and that the system runs smoothly.

Process State: As a process executes, it changes state. The process. Each process may be in one of the
following

• New: The process is being created.

• Running: Instructions are being

• Waiting: The process is waiting reception of a signal).

• Ready: The process is waiting

• Terminated: The process has


[Link] the process is created (new), the operating system puts it into the ready queue.

2. When its turn comes, the operating system dispatches it to the running state (by using

scheduling algorithms) by loading the CPU registers with values, stored in the registers save

area.

3. While running, if the process wants to perform some I/O operations, the operating system

suspends that process and passes it to the waiting queue and takes up the next ready

process for processing.

4. When the I/O for the process for processing waiting queue is completed, the hardware

generates an interrupt, and then operating system changes the state of process to ready and

pass it to ready queue. The process can again be dispatched when it turn arrives.

5. The whole cycle is repeated until the process is terminated.

6. After termination, the operating system removes all the details of process from memory,

de-allocates all the resources assigned to the terminated process and takes next process

from the ready queue for execution.

7. The time is allocated to execute a process, known as time slice, in some algorithm. This is

done so that a process does not use the CPU indefinitely, when the time slice for a process is

over, operating system puts the process in ready queue by interrupting and change the state

of process to ready state. It will not pass to waiting queue as it is not waiting for any external

event.
Process Control Block (PCB):
• Each process is represented in the operating system by a process control block (PCB)- also called a
task control block.

• A PCB is shown in Figure

• It contains many pieces of information associated with a specific process, including these:

Process Id

Process State

Program Counter

Registers

File List

I/O Info

Protection

Process-id:

Process-id is a number allocated by the operating system to the process on creation. This number is
used for carrying out any operation on the process.

Process state:

The state may be new, ready, running, waiting, halted, and terminated.

Program counter:

The counter indicates the address of the next instruction to be executed for this process.

Registers in the PCB

• When a process is running, the CPU uses its registers to store the process's current
working data.
• If the operating system needs to interrupt the process (for example, to switch to
another process), it must save the current state of those registers.

File Lists in Process Control Blocks (PCBs):

• When an operating system manages a running process, the PCB holds information
about the files that the process is currently using. This typically includes:
o Open file descriptors: These are numerical identifiers that the operating
system uses to track open files.
o File pointers: These indicate the current position within an open file.
o File access rights: These specify what the process is allowed to do with the
file (e.g., read, write, execute).

I/O Information in a PCB:

• Tracking I/O Operations:


o The operating system needs to keep track of which I/O operations a process
has requested, their status, and the devices involved.
• Managing I/O Resources:
o The PCB helps the OS allocate and deallocate I/O devices to processes,
preventing conflicts.
• Handling I/O Interrupts:
o When an I/O device completes an operation, it generates an interrupt. The OS
uses the I/O information in the PCB to determine which process should be
notified.

Types of Resources to Protect:

• Memory: Preventing processes from accessing each other's memory spaces.


• CPU: Controlling how processes share CPU time.
• Files: Regulating access to files and directories.
• I/O Devices: Managing access to peripherals like printers, disks, and network
interfaces.
• System Resources: Protecting system tables, data structures, and kernel code.

Schedulers
In an operating system, schedulers are essential components that determine which process
gets to use the CPU at any given time. They're crucial for managing multitasking, ensuring
efficient resource utilization, and providing a responsive user experience. Here's a breakdown
of the different types of schedulers:

Types of Schedulers:

Operating systems typically employ three main types of schedulers:

• Long-Term Scheduler (Job Scheduler):


o This scheduler controls the degree of multiprogramming, which is the number
of processes in memory.
o It selects processes from the job queue (a queue of processes waiting to be
brought into memory) and loads them into memory for execution.
o It aims to maintain a good mix of CPU-bound and I/O-bound processes.
o It is less frequent in execution compared to the short term scheduler.
• Short-Term Scheduler (CPU Scheduler):
o This scheduler selects which process should be executed next and allocates the
CPU to it.
o It operates very frequently, as it needs to make decisions whenever a process
switches states (e.g., from ready to running, or running to waiting).
o It is responsible for maximizing CPU utilization and minimizing response
time.
• Medium-Term Scheduler:
o This scheduler is involved in swapping processes in and out of memory.
o It removes processes from memory (swaps them out) to reduce the degree of
multiprogramming and free up memory.
o It can later swap processes back into memory (swaps them in) to resume their
execution.
o This is very useful for managing memory, and for when a process becomes
suspended.

Process Switch / Context switch

1. The CPU switching from one process to another requires saving the state of the current process &
loading the latest state of the next process. This is known as context switch.
2 .The context of a process is represented in the PCB of a process; it includes the value of the CPU
registers, the process state and memory-management information.
3 .When a context switch occurs, the kernel saves the context of the old process in its PCB and loads
the saved context of the new process scheduled to run.
4 .Context-switch time is pure overhead, because the system does no useful work while switching.
5 .Its speed varies from machine to machine, depending on the memory speed, the number of registers
that must be copied, and the existence of special instructions (such as a single instruction to load or
store all registers).
6 .Typical speeds range from 1 to 1000 microseconds.
7 .Context-switch times are highly dependent on hardware support.
Interprocess Communication
• Inter process communication means the process are communicating with each other while they are
running.

• Processes executing concurrently in the operating system may be either independent processes or
cooperating processes.

• A process is independent if it cannot affect or be affected by the other processes executing in the
system. Any process that does not share data with any other process is independent.

• A process is cooperating if it can affect or be affected by the other processes executing in the
system. Any process that shares data with other processes is a cooperating process.

There are several reasons for providing an environment that allows process cooperation:

• Information sharing. Since several users may be interested in the same piece of information (for
instance, a shared file), we must provide an environment to allow concurrent access to such
information.

• Computation speedup. If we want a particular task to run faster, we must break it into subtasks, each
of which will be executing in parallel with the others. Notice that such a speedup can be achieved only
if the computer has multiple processing elements (such as CPUs or I/O channels).

• Modularity. We may want to construct the system in a modular fashion, dividing the system
functions into separate processes or threads.

• Convenience. Even an individual user may work on many tasks at the same time. For instance, a
user may be editing, printing, and compiling in parallel.

Cooperating processes require an inter-process communication (IPC) mechanism that will allow them
to exchange data and information.

There are two fundamental models of inter-process communication:

(1) Shared memory and

(2) Message passing.

In the shared-memory model, a region of memory that is shared by cooperating processes is


established. Processes can then exchange information by reading and writing data to the shared
region.

In the message passing model, communication takes place by means of messages exchanged between
the cooperating processes.
The two communications models are contrasted in Figure.

Both of the models are common in operating systems, and many systems implement both. Message
passing is useful for exchanging smaller amounts of data, because no conflicts need be avoided.
Message passing is also easier to implement than is shared memory for inter- computer
communication. Shared memory allows maximum speed and convenience of communication, as it
can be done at memory speeds when within a computer. Shared memory is faster than message
passing, as message-passing systems are typically implemented using system calls and thus require
the more time consuming task of kernel intervention. In shared-memory systems, system calls are
required only to establish shared-memory regions. Once shared memory is established, all accesses
are treated as routine memory accesses, and no assistance from the kernel is required.

Shared-Memory Systems
• Inter-process communication using shared memory requires communicating processes to establish a
region of shared memory.

• A shared-memory region resides in the address space of the process creating the shared- memory
segment.

• Other processes that wish to communicate using this shared-memory segment must attach it to their
address space.

• They can then exchange information by reading and writing data in the shared areas.
• The form of the data and the location are determined by these processes and are not under the
operating system's control.

• The processes are also responsible for ensuring that they are not writing to the same

location simultaneously

Message-Passing Systems
In Shared memory scheme requires that the processes share a region of memory and that the code for
accessing and manipulating the shared memory be written explicitly by the application programmer.
Another way to achieve the same effect is via a message-passing facility. Message passing provides a
mechanism to allow processes to communicate and to synchronize their actions without sharing the
same address space and is particularly useful in a distributed environment, where the communicating
processes may reside on different computers connected by a network. For example, a chat program
used on the World Wide Web could be designed so that chat participants communicate with one
another by exchanging messages.

You might also like