A process is the basic unit of execution in an operating system. When a program is loaded into memory, it becomes a process. A process consists of code, data, a heap, and a stack. Processes go through various states in their lifecycle including new, ready, running, waiting, terminated, suspended ready, and suspended wait.
The operating system maintains information about each process using a Process Control Block (PCB). The PCB contains information like the process state, ID, program counter, scheduling information, and I/O status.
When a process creates another process, the original process is called the parent process and the new process is called the child process. Parent and child processes can execute concurrently
3. Process
▶ Process is a program in execution. A process is the
basic unit of execution in an operating system.
▶ When a program is loaded into the memory and it
becomes a process.
4. Process parts
▶ Program: (Code/text) A program is a piece of code which may
be a single line or millions of lines.
▶ Data: This section contains the global and static variables.
▶ Heap: Contains memory dynamically allocated during run time.
▶ Stack: Temporary Data like function parameters, return addresses,
local variable.
5. Process life cycle
Processes may be in one of 5 states.
▶ New - The process is in the stage of being created.
▶ Ready - The process has all the resources available that it needs to
run, but the CPU is not currently working on this process's
instructions.
▶ Running - The CPU is working on this process's instructions.
▶ Waiting - The process cannot run at the moment, because it is
waiting for some resource to become available or for some event
to occur. For example the process may be waiting for keyboard
input, inter-process messages, or a child process to finish.
▶ Terminated - The process has completed.
7. Process life cycle
There is also a suspended stage in some cases
▶ Suspend ready - if a process is in ready state and a more priority
process arrives then the previous process is sent to suspend ready
state (inside the secondary memory)
▶ Suspend wait - if a process is in wait or block state and a more
priority process arrives then the previous process is sent to suspend
block state (inside the secondary memory)
▶ as soon as the ready or block state is empty it is sent to ready or
block state respectively.
8. Process Control Block
A Process Control Block is a data structure maintained by the
Operating System for every process. The PCB is identified by an
integer process ID (PID). A PCB keeps all the information
needed to keep track of a
process
9. PCB
Process State
The current state of the process i.e., whether it is ready, running, waiting, or whatever.
▶ Process privileges
This is required to allow/disallow access to system resources.
▶ Process ID
Unique identification for each of the process in the operating system
▶ Program Counter
Program Counter is a pointer to the address of the next instruction to be executed for this
process.
▶ CPU Scheduling Information
Process priority and other scheduling information which is required to schedule the process.
▶ IO status information
This includes a list of I/O devices allocated to the process.
10. Parent and Child Process
▶ Process creation
▶ Parent: Creating process
▶ Child: New process(created by parent)
▶ Parent process create children processes which in turn create
other processes forming a three of processes. Generally,
process identifier and managed via a PID.
(A child process is a replica of the parent process and shares
some or all of its resources)
11. Process creation
▶ Resource sharing
▶ Parent and children share all resources.
▶ Children share subset of parent's resources.
▶ Parent and child share no resources.
▶ Execution
▶ Parent and children execute concurrently.
▶ Parent waits until children terminate.
13. Process termination
▶ Process executes last statement and ask the operating system
to delete it(exit).
▶ Output data from child to parent.
▶ Process resources are de allocated by OS.
▶ Parent may terminate execution of child processes.
▶ Child has exceeded allocated resources.
▶ Task assigned to child is no longer required.
▶ Some OS don't allow child to continue it its parent terminates
it's called cascading termination.
14. Inter-process communication
We may divide the process as dependent or independent
processes:
▶ Independent Processes that can neither affect other
processes or be affected by other processes.
▶ Cooperating Processes or dependent process are those that
can affect or be affected by other processes.
15. Why cooperating processes are
allowed?
Reasons why cooperating processes are allowed are:
▶ Information Sharing - There may be several processes
which need access to the same file
▶ Modularity - The most efficient architecture may be to
break a system down into cooperating modules. ( E.g.
databases with a client-server architecture. )
▶ Convenience - Even a single user may be multi-
tasking, such as editing, compiling, printing, and
running the same code in different windows.