Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

9 cm402.13

495 views

Published on

  • Be the first to comment

  • Be the first to like this

9 cm402.13

  1. 1. UNDERSTAND PROCESS MANAGEMENT:Process Creation and TerminationHOME PREVIOUS TOPIC NEXTPREVIOUS QUESTION PAPERS FOR OSCPP TUTORIALS 1
  2. 2. RecapIn the last class, you have learnt• Understand the Structure of Process Control Block 2
  3. 3. ObjectivesOn completion of this class, you would be able to know• Process Creation• Process Termination 3
  4. 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. 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. 6. RootPagedaemon Swapper init User 1 User 2 User 3 Fig: 1 - Tree of Processes 6
  7. 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 subprocess obtains its resources • Directly from the operating system OR • It may be constrained to a subset of the resources of parent process 7
  8. 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. 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. 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. 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. 12. Process CreationTo 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 25. Summary In this class, you have learnt• Process creation• Process termination• Systems calls exec(), wait(), exit(), execlp() 25
  26. 26. Frequently Asked Questions1) Explain process creation2) Explain process termination3) List out the system calls in process creation4) What are the reasons for a parent may terminate the execution of one of its children? 26
  27. 27. Quiz1) The creating process is called a …………..a) Left childb) Parentc) Right child 27
  28. 28. Quiz2. The new processes are called the ……….. Of that process.a) Childrenb) Parentc) None of the above 28
  29. 29. Quiz3) A new process is created by the ………. System call.a) fork()b) Exec()c) Wait() 29
  30. 30. Quiz4) Process is deleted by using the ………. System call.a) fork()b) Exec()c) Wait()d) exit( ) 30
  31. 31. Other subject materials• Web designing• Micro processors• C++ tutorials• javahome

×