processes
OUTLINE
 Process Concept
 Process Scheduling
 Operations on Processes
 Inter-process Communication
 Examples of IPC Systems
 Communication in Client-Server Systems
Fork( ) ?
Fork( ) ?
Fork( ) ?
Fork( ) ?
Fork( ) ?
Fork( ) ?
Fork( ) ?
Fork( ) ?
Process creation
 A process may create several processes during the execution.
 Creating process is called a parent and a created process is called a
child.
 Parent process create children process, which, in turn create other
processes, forming a tree of processes
 Generally, process identified and managed via a process identifier (pid)
Process creation: fork()
 Creates a child process.
 Child process contains exact copy of the memory space of the parent
process.
 Child process contains the same text/code section but executes
independently
Exec()
 Exec is a collection of function e.g., execlp(), ececve(), execl(), are use to
execute any program/script.
 Typically exec used after a fork() by child process to replace the memory
space with a new program.
 PID does not change but the data, heap, and stack of the child are
replace by new program
Process creation (cont..)
 Fork( ) system call creates new process
 Exec( ) system call used after fork to replace the process memory space
with a new program.
Process Termination
 Process executes last statement and asks the operating system to delete it
(exit)
 Process resources are deallocated by operating system
 Parent may terminate execution of children processes (abort).
 Task assigned to child is no longer required
 If parent is exiting
o Some operating system do not allow to continue if its parent
terminates
o All children terminated – cascading termination.
15
Execution Trace: fork()
RAM
CPU
Kernel
stack
data
text
….
n=fork();
If (n == 0)
..
else if (n>0)
...
PC
PCB-Parent
Process-Parent
x pid
PC
n
sys_fork()
{….}
PC
y pid
PCB-Child
text
Process-Child
n
stack
data
….
n=fork();
If (n == 0)
..
else if (n>0)
...
y 0
16
Execution Trace: fork() with execlp()
RAM
CPU
Kernel
stack
data
text
….
n=fork();
If (n == 0)
…exec()
else if (n>0)
...
PC
PCB-Parent
Process-Parent
x pid
PC
n
sys_fork()
{….}
PC
y pid
PCB-Child
text
Process-Child
n
stack
data
….
n=fork();
If (n == 0)
…exec()
else if (n>0)
...
y 0
sys_execve()
{….}
new code

Chapter3_ProcessConcept-Operation_on_Processes.pptx

  • 1.
    processes OUTLINE  Process Concept Process Scheduling  Operations on Processes  Inter-process Communication  Examples of IPC Systems  Communication in Client-Server Systems
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
    Process creation  Aprocess may create several processes during the execution.  Creating process is called a parent and a created process is called a child.  Parent process create children process, which, in turn create other processes, forming a tree of processes  Generally, process identified and managed via a process identifier (pid)
  • 11.
    Process creation: fork() Creates a child process.  Child process contains exact copy of the memory space of the parent process.  Child process contains the same text/code section but executes independently
  • 12.
    Exec()  Exec isa collection of function e.g., execlp(), ececve(), execl(), are use to execute any program/script.  Typically exec used after a fork() by child process to replace the memory space with a new program.  PID does not change but the data, heap, and stack of the child are replace by new program
  • 13.
    Process creation (cont..) Fork( ) system call creates new process  Exec( ) system call used after fork to replace the process memory space with a new program.
  • 14.
    Process Termination  Processexecutes last statement and asks the operating system to delete it (exit)  Process resources are deallocated by operating system  Parent may terminate execution of children processes (abort).  Task assigned to child is no longer required  If parent is exiting o Some operating system do not allow to continue if its parent terminates o All children terminated – cascading termination.
  • 15.
    15 Execution Trace: fork() RAM CPU Kernel stack data text …. n=fork(); If(n == 0) .. else if (n>0) ... PC PCB-Parent Process-Parent x pid PC n sys_fork() {….} PC y pid PCB-Child text Process-Child n stack data …. n=fork(); If (n == 0) .. else if (n>0) ... y 0
  • 16.
    16 Execution Trace: fork()with execlp() RAM CPU Kernel stack data text …. n=fork(); If (n == 0) …exec() else if (n>0) ... PC PCB-Parent Process-Parent x pid PC n sys_fork() {….} PC y pid PCB-Child text Process-Child n stack data …. n=fork(); If (n == 0) …exec() else if (n>0) ... y 0 sys_execve() {….} new code