SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Downloaden Sie, um offline zu lesen
UNDERSTAND PROCESS
    MANAGEMENT
:




Process Creation and Termination




HOME     PREVIOUS TOPIC NEXT
PREVIOUS QUESTION PAPERS FOR OS
CPP TUTORIALS
                                   1
Recap


In the last class, you have learnt
•   Understand the Structure of Process Control
    Block




                                                  2
Objectives


On completion of this class, you would be able to
    know
•   Process Creation
•   Process Termination




                                                    3
Operations on Process


• The process in most systems can execute concurrently,

  and they may be Created and Deleted Dynamically

• Operating systems must provide a mechanism for

  process creation and termination




                                                          4
Process Creation

• Process may create several new processes via a “create-
  process” system call
• The creating process is called a “Parent Process”

• The new processes are called “Children Process”

• Each of these new process may in turn create other
  processes
• Forming a tree of process as shown in Fig( 1 ) in next slide



                                                           5
Root




Pagedaemon   Swapper        init



             User 1        User 2           User 3




               Fig: 1 - Tree of Processes
                                                     6
Process Creation

•A process needs certain resources like CPU time,
Memory, Files, I/O devices to accomplish its task

•When a process creates a sub process, that sub
process obtains its resources

  • Directly from the operating system

                   OR

  • It may be constrained to a subset of the resources of
  parent process                                            7
Process Creation

• The parent process may have to partition its resources
  among its children (or)

• It has to share some resources such as memory or file
  among several of its children

• Restricting a child process to a subset of the parent’s
  resources prevents any process from over loading the
  system by creating too many sub processes


                                                            8
Process Creation
• A process obtains various physical and logical resources
  when it is created
• In addition to the above, initialization data is also passed
  by the parent process to the child process
• For example
   – A Process whose function is to display the contents a
     file F1 on the screen of a terminal When it is created
   – It will get, the name of the file F1 as a input from its
     parent process
   – It will use that file name, open the file and write the
     contents out
                                                                 9
Process Creation


• When a process creates a new process, two

  possibilities exist in terms of execution
   1. The parent continues to execute concurrently with its

     children

   2. The parent waits until some or all of its children have

     terminated


                                                            10
Process Creation


•    There are also two possibilities in terms

     address space of the new process

    1. The child process is a duplicate of the parent process

    2. The child process has a new program loaded into it




                                                            11
Process Creation
To illustrate these differences
• Let us consider the UNIX, operating system

• In UNIX, each process is identified by its process
  identifier, which is a unique integer

• A new process is created by the fork( ) system call

• The process consists of a copy of the address space of
  the original process

• This mechanism allows the parent process to
  communicate easily with its child process
                                                           12
Process Creation

• Both process the parent and the child continue execution

  at the instruction after the fork(), with one difference

• The return code for the fork() is zero for the (new), child

  process

• Where as the (non zero) process identifier of the child is

  returned to the parent


                                                                13
Process Creation Execlp ()
• The execlp() system call is used after a fork() system call
  by one of the two processes
   – To replace the processes memory space with a new program

• The execlp() system call loads a binary file into memory
  and starts its execution
• Parent can issue a wait() system call to move itself off
  the ready queue until the termination of the child



                                                                14
/* C program forking a separate process */
    #include<stdio. h>
    #include<unistd.h>
    int main(int argc, char *argv[])
{
    int pid;
    /*fork another process */
    pid=fork();
    if (pid<0) {/*error occurred*/
    fprintf(stderr, “fork failed”);
    exit(-1);
         }
                                       Continue..
                                                    15
else if(pid==0){/*child process*/
    execlp(“/bin/ls”, “ls”, NULL);
       }
    else{/*parent process*/
    /*parent will wait for the child to complete*/
     wait(NULL);
     printf(“child complete”);
     exit(0);
         }
}

                                                     16
Process Termination

• A Process terminates when it finishes executing
  its final statement
• Asks the operating system to delete it by using
  exit( ) system call
• At that point, the process may return a status
  value to its parent process


                                                    17
Process Termination

• All the resources of the process including
  • Physical Memory
  • Virtual Memory
  • Open Files
  • I/O Buffers

 are de allocated by the operating system



                                               18
Process Termination

• Termination can occur in other circumstances as well

• A process can cause the termination of another process

  via an appropriate system call

      Example: abort();

• Usually, such a system call can be invoked only by the

  parent of the process that is to be terminated


                                                           19
Process Termination

• Otherwise, users could arbitrarily kill each others
  jobs
• Note that a parent needs to know the identities of
  its children
• Thus, when one process creates a new process
• The identity of the newly created process is
  passed to the parent

                                                    20
Process Termination

• A parent may terminate the execution of one of
  its children for a variety of reasons, such as:
• The child has exceeded its usage of 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

                                                     21
Process Termination

• If a process terminates then all its children must
  also be terminated

• This phenomenon, is referred to as cascading
  termination is normally initiated by the operating
  system

• We can terminate a process by using the exit ()
  system call in UNIX
                                                    22
Process Termination

• Its parent process may wait for the termination
  of a child process by using the wait() system call
• The wait() system call returns the process
  identifier of a terminated child
• So that the parent can tell which of its possibly
  many children has terminated


                                                      23
Process Termination

• If the parent terminate, however, all its children have
  assigned as their new parent the init process

• Thus the children still have a parent to collect their status
  and execution statistics




                                                             24
Summary


 In this class, you have learnt
• Process creation

• Process termination

• Systems calls exec(), wait(), exit(), execlp()




                                                   25
Frequently Asked Questions

1)   Explain process creation

2)   Explain process termination

3)   List out the system calls in process creation

4)   What are the reasons for a parent may terminate the
     execution of one of its children?




                                                           26
Quiz

1)   The creating process is called a …………..
a)   Left child
b)   Parent
c)   Right child




                                               27
Quiz

2. The new processes are called the ……….. Of that
    process.
a) Children
b) Parent
c) None of the above




                                                    28
Quiz

3) A new process is created by the ………. System call.
a) fork()
b) Exec()
c) Wait()




                                                       29
Quiz

4) Process is deleted by using the ………. System call.
a) fork()
b) Exec()
c) Wait()
d) exit( )




                                                       30
Other subject materials

•   Web designing
•   Micro processors
•   C++ tutorials
•   java

home

Weitere ähnliche Inhalte

Ähnlich wie 9 cm402.13

Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...Shivam Mitra
 
Course 102: Lecture 18: Process Life Cycle
Course 102: Lecture 18: Process Life CycleCourse 102: Lecture 18: Process Life Cycle
Course 102: Lecture 18: Process Life CycleAhmed El-Arabawy
 
Process creation and termination In Operating System
Process creation and termination In Operating SystemProcess creation and termination In Operating System
Process creation and termination In Operating SystemFarhan Aslam
 
Processes, Threads.pptx
Processes, Threads.pptxProcesses, Threads.pptx
Processes, Threads.pptxLECO9
 
Processes, Threads.pptx
Processes, Threads.pptxProcesses, Threads.pptx
Processes, Threads.pptxSKUP1
 
04_ForkPipe.pptx
04_ForkPipe.pptx04_ForkPipe.pptx
04_ForkPipe.pptxvnwzympx
 
Systems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesSystems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesHelpWithAssignment.com
 
11 process definition
11 process definition11 process definition
11 process definitionmyrajendra
 
Chapter 02 modified
Chapter 02 modifiedChapter 02 modified
Chapter 02 modifiedJugal Doshi
 
Chapter -2 operating system presentation
Chapter -2 operating system presentationChapter -2 operating system presentation
Chapter -2 operating system presentationchnrketan
 
Tarea - 3 Actividad intermedia trabajo colaborativo 2
Tarea - 3 Actividad intermedia trabajo colaborativo 2Tarea - 3 Actividad intermedia trabajo colaborativo 2
Tarea - 3 Actividad intermedia trabajo colaborativo 2HectorFabianPintoOsp
 
UNIT-2-Process-Management.pdf
UNIT-2-Process-Management.pdfUNIT-2-Process-Management.pdf
UNIT-2-Process-Management.pdfaakritii765
 
Ch2_Processes_and_process_management_1.ppt
Ch2_Processes_and_process_management_1.pptCh2_Processes_and_process_management_1.ppt
Ch2_Processes_and_process_management_1.pptMohammad Almuiet
 
opearating system notes mumbai university.pptx
opearating system notes mumbai university.pptxopearating system notes mumbai university.pptx
opearating system notes mumbai university.pptxssuser3dfcef
 

Ähnlich wie 9 cm402.13 (20)

Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...
 
Lect3 process
Lect3 processLect3 process
Lect3 process
 
Course 102: Lecture 18: Process Life Cycle
Course 102: Lecture 18: Process Life CycleCourse 102: Lecture 18: Process Life Cycle
Course 102: Lecture 18: Process Life Cycle
 
Process creation and termination In Operating System
Process creation and termination In Operating SystemProcess creation and termination In Operating System
Process creation and termination In Operating System
 
3 process management
3 process management3 process management
3 process management
 
Processes, Threads.pptx
Processes, Threads.pptxProcesses, Threads.pptx
Processes, Threads.pptx
 
Processes, Threads.pptx
Processes, Threads.pptxProcesses, Threads.pptx
Processes, Threads.pptx
 
Lecture 2 process
Lecture 2   processLecture 2   process
Lecture 2 process
 
04_ForkPipe.pptx
04_ForkPipe.pptx04_ForkPipe.pptx
04_ForkPipe.pptx
 
Systems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesSystems Programming Assignment Help - Processes
Systems Programming Assignment Help - Processes
 
Lecture5
Lecture5Lecture5
Lecture5
 
Operating Systems
Operating Systems Operating Systems
Operating Systems
 
11 process definition
11 process definition11 process definition
11 process definition
 
Chapter 02 modified
Chapter 02 modifiedChapter 02 modified
Chapter 02 modified
 
Chapter -2 operating system presentation
Chapter -2 operating system presentationChapter -2 operating system presentation
Chapter -2 operating system presentation
 
Tarea - 3 Actividad intermedia trabajo colaborativo 2
Tarea - 3 Actividad intermedia trabajo colaborativo 2Tarea - 3 Actividad intermedia trabajo colaborativo 2
Tarea - 3 Actividad intermedia trabajo colaborativo 2
 
UNIT-2-Process-Management.pdf
UNIT-2-Process-Management.pdfUNIT-2-Process-Management.pdf
UNIT-2-Process-Management.pdf
 
Ch2_Processes_and_process_management_1.ppt
Ch2_Processes_and_process_management_1.pptCh2_Processes_and_process_management_1.ppt
Ch2_Processes_and_process_management_1.ppt
 
OS (1).pptx
OS (1).pptxOS (1).pptx
OS (1).pptx
 
opearating system notes mumbai university.pptx
opearating system notes mumbai university.pptxopearating system notes mumbai university.pptx
opearating system notes mumbai university.pptx
 

Mehr von myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
2. attributes
2. attributes2. attributes
2. attributes
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 

9 cm402.13

  • 1. UNDERSTAND PROCESS MANAGEMENT : Process Creation and Termination HOME PREVIOUS TOPIC NEXT PREVIOUS QUESTION PAPERS FOR OS CPP TUTORIALS 1
  • 2. Recap In the last class, you have learnt • Understand the Structure of Process Control Block 2
  • 3. Objectives On completion of this class, you would be able to know • Process Creation • Process Termination 3
  • 4. Operations on Process • The process in most systems can execute concurrently, and they may be Created and Deleted Dynamically • Operating systems must provide a mechanism for process creation and termination 4
  • 5. Process Creation • Process may create several new processes via a “create- process” system call • The creating process is called a “Parent Process” • The new processes are called “Children Process” • Each of these new process may in turn create other processes • Forming a tree of process as shown in Fig( 1 ) in next slide 5
  • 6. Root Pagedaemon Swapper init User 1 User 2 User 3 Fig: 1 - Tree of Processes 6
  • 7. Process Creation •A process needs certain resources like CPU time, Memory, Files, I/O devices to accomplish its task •When a process creates a sub process, that sub process obtains its resources • Directly from the operating system OR • It may be constrained to a subset of the resources of parent process 7
  • 8. Process Creation • The parent process may have to partition its resources among its children (or) • It has to share some resources such as memory or file among several of its children • Restricting a child process to a subset of the parent’s resources prevents any process from over loading the system by creating too many sub processes 8
  • 9. Process Creation • A process obtains various physical and logical resources when it is created • In addition to the above, initialization data is also passed by the parent process to the child process • For example – A Process whose function is to display the contents a file F1 on the screen of a terminal When it is created – It will get, the name of the file F1 as a input from its parent process – It will use that file name, open the file and write the contents out 9
  • 10. Process Creation • When a process creates a new process, two possibilities exist in terms of execution 1. The parent continues to execute concurrently with its children 2. The parent waits until some or all of its children have terminated 10
  • 11. Process Creation • There are also two possibilities in terms address space of the new process 1. The child process is a duplicate of the parent process 2. The child process has a new program loaded into it 11
  • 12. Process Creation To illustrate these differences • Let us consider the UNIX, operating system • In UNIX, each process is identified by its process identifier, which is a unique integer • A new process is created by the fork( ) system call • The process consists of a copy of the address space of the original process • This mechanism allows the parent process to communicate easily with its child process 12
  • 13. Process Creation • Both process the parent and the child continue execution at the instruction after the fork(), with one difference • The return code for the fork() is zero for the (new), child process • Where as the (non zero) process identifier of the child is returned to the parent 13
  • 14. Process Creation Execlp () • The execlp() system call is used after a fork() system call by one of the two processes – To replace the processes memory space with a new program • The execlp() system call loads a binary file into memory and starts its execution • Parent can issue a wait() system call to move itself off the ready queue until the termination of the child 14
  • 15. /* C program forking a separate process */ #include<stdio. h> #include<unistd.h> int main(int argc, char *argv[]) { int pid; /*fork another process */ pid=fork(); if (pid<0) {/*error occurred*/ fprintf(stderr, “fork failed”); exit(-1); } Continue.. 15
  • 16. else if(pid==0){/*child process*/ execlp(“/bin/ls”, “ls”, NULL); } else{/*parent process*/ /*parent will wait for the child to complete*/ wait(NULL); printf(“child complete”); exit(0); } } 16
  • 17. Process Termination • A Process terminates when it finishes executing its final statement • Asks the operating system to delete it by using exit( ) system call • At that point, the process may return a status value to its parent process 17
  • 18. Process Termination • All the resources of the process including • Physical Memory • Virtual Memory • Open Files • I/O Buffers are de allocated by the operating system 18
  • 19. Process Termination • Termination can occur in other circumstances as well • A process can cause the termination of another process via an appropriate system call Example: abort(); • Usually, such a system call can be invoked only by the parent of the process that is to be terminated 19
  • 20. Process Termination • Otherwise, users could arbitrarily kill each others jobs • Note that a parent needs to know the identities of its children • Thus, when one process creates a new process • The identity of the newly created process is passed to the parent 20
  • 21. Process Termination • A parent may terminate the execution of one of its children for a variety of reasons, such as: • The child has exceeded its usage of 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 21
  • 22. Process Termination • If a process terminates then all its children must also be terminated • This phenomenon, is referred to as cascading termination is normally initiated by the operating system • We can terminate a process by using the exit () system call in UNIX 22
  • 23. Process Termination • Its parent process may wait for the termination of a child process by using the wait() system call • The wait() system call returns the process identifier of a terminated child • So that the parent can tell which of its possibly many children has terminated 23
  • 24. Process Termination • If the parent terminate, however, all its children have assigned as their new parent the init process • Thus the children still have a parent to collect their status and execution statistics 24
  • 25. Summary In this class, you have learnt • Process creation • Process termination • Systems calls exec(), wait(), exit(), execlp() 25
  • 26. Frequently Asked Questions 1) Explain process creation 2) Explain process termination 3) List out the system calls in process creation 4) What are the reasons for a parent may terminate the execution of one of its children? 26
  • 27. Quiz 1) The creating process is called a ………….. a) Left child b) Parent c) Right child 27
  • 28. Quiz 2. The new processes are called the ……….. Of that process. a) Children b) Parent c) None of the above 28
  • 29. Quiz 3) A new process is created by the ………. System call. a) fork() b) Exec() c) Wait() 29
  • 30. Quiz 4) Process is deleted by using the ………. System call. a) fork() b) Exec() c) Wait() d) exit( ) 30
  • 31. Other subject materials • Web designing • Micro processors • C++ tutorials • java home