Processes
Processes
4th Lec
Processes
• Process is a program in execution.
• Process is equal to the Job in older system e,g in batch OS or Task in
Linux system.
• Current Processes, the status of the current activity of a process is
represented by the program counter and other registers of a CPU.
• In modern systems there are four or eight or more CPUs (cores)
available, there could be dozens or hundreds of processes running.
Processes Concepts
• Text section— the executable code
• Data section—global variables,
initialized and uninitialized
• Heap section—a memory that is
dynamically allocated during
program run time
• Stack section— temporary data
storage when invoking functions
(such as function parameters, return
addresses, and local variables)
Layout of a process in memory
Multiprocessing Concept
• A multiprogramming system supporting multiple processes execute
concurrently.
• Simple computing devices like smartphones and tablets can support
multiple processes.
• Multiple processors also creates multiprogramming.
• In any multiprogramming system, each CPU switches from process to
process quickly.
• At any one instant each CPU(Core) is running only one process. In the
course of 1 second, it may work on several of them, giving the illusion
of parallelism.
Process Control Block
• Each process is represented in the operating system by a process
control block (PCB), also called a task control block, it contains
following.
• Process state. The state may be new, ready, running, waiting, halted,
and so on.
• Program counter. The counter indicates the address of the next
instruction to be executed for this process
• CPU registers. AC, IR, SP, BP, special purpose, and general-purpose
registers. The registers vary in number and type, depending on the
computer architecture.
Process Control Block
• CPU-scheduling information. This information includes a process
priority, pointers to scheduling queues, and any other scheduling
parameters.
• Memory-management information. Base and limit registers and the
page tables, or the segment tables, depending on the memory system
used by the operating system.
• Accounting information. This information includes the amount of CPU
and real-time used, time limits, account numbers, job or process
numbers, and so on.
Process Control Block
• I/O status information. This information includes the list of I/O devices
allocated to the process, a list of open files, and so on.
In brief, the PCB simply serves as the repository for all the data needed
to start, or restart, a process, along with some accounting data.
Process State
• The state of a process is defined in part by the current activity of that
process. A process may be in one of the following States.
• New. The process is being created.
• Running. Instructions are being executed.
• Waiting. The process is waiting for some event to occur (such as an
I/O completion or reception of a signal).
• Ready. The process is waiting to be assigned to a processor.
• Terminated. The process has finished execution.
Process State
Process Scheduling
• In general, most processes can be described as either I/O bound
or CPU bound.
• The objective of multiprogramming is to keep the CPU busy by
using process scheduling.
• The number of processes currently in memory is known as the
degree of multiprogramming.
Scheduling Queues
• Process entered in CPU for
execution, will enter in the ready
queue.
• Process when interrupted or
waiting for an I/O event, moved
towards the wait queue.
Scheduling Queues
CPU Scheduling
• Process migrates among the ready queue and various wait queues
throughout its lifetime.
• An I/O-bound process may execute for only a few milliseconds before
waiting for an I/O request.
• CPU-bound processes will require a CPU core for longer durations.
• Some operating systems have an intermediate form of scheduling,
known as swapping.
• Swapping is to remove a process from memory (and from active
contention for the CPU) and thus reduce the degree of
multiprogramming.
Context Switching
• Switching the CPU core to another process requires performing a
state save of the current process and a state restore of a different
process. This task is known as a context switch
• Interrupt Occurrence, Time out, etc triggers context switching.
• Context-switch times are highly dependent on hardware support.
Context
Switching
Operations on Processes
• The processes in most systems can execute concurrently, and they
may be created and deleted dynamically.
• process creation and termination mechanism must be defined.
Process Creation:
• A process may create several new processes (Parent and Child
processes).
• Tree structure
• Unique process identifier (or pid)
Creating a processes
Creating a processes
• When a process creates a new process, two possibilities for execution
exist:
1. The parent continues to execute concurrently with its children.
2. The parent waits until some or all of its children have terminated.
For Address spacing possibilities.
3. The child process is a duplicate of the parent process (Copy of
address space of parent).
4. The child process has a new program loaded into it.
Process Termination
• A process terminates when it finishes executing its final statement.
There can be normal and abnormal termination.
A parent may terminate the execution of one of its children for a
variety of reasons, such as these:
• The child has exceeded its usage of some of the resources that it has
been allocated.
• The task assigned to the child is no longer required.
• The parent is exiting, and the operating system does not allow a child
to continue if its parent terminates.
Android Process Hierarchy
• Foreground process—The current process visible on the screen,
representing the application the user is currently interacting with
• Visible process—A process that is not directly visible on the
foreground but that is performing an activity that the foreground
process is referring to (that is, a process performing an activity whose
status is displayed on the foreground process)
• Service process—A process that is similar to a background process but
is performing an activity that is apparent to the user (such as
streaming music)
Android Process Hierarchy
• Background process—A process that may be performing an activity
but is not apparent to the user.
• Empty process—A process that holds no active components
associated with any application