Process creation


Published on

Published in: Business, Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Process creation

  1. 1. Process Creation in UNIXPresentation by K.GautamPresented byK.Gautam and Ashok
  2. 2. Creation of a Process fork system call. Invoker is Parent and Invokee is Child pid = fork();
  3. 3. Return from fork() The two processes have identical copies of their user-level context In the parent process, pid is the child process ID; in the child process, pid is 0.
  4. 4. Process 0 created internally by the kernel when the system is booted, is the only process not created via fork.
  5. 5. The kernel operations for fork.1)It allocates a slot in the process table for the new process.2)It assigns a unique ID number to the child process.3)It makes a logical copy of the context of the parent process. .4)It increments file and inode table counters for files associated with the process.5)It returns the ID number of the child to the parent process, and a 0 value to the child process.
  7. 7. algorithm fork input: none output: to parent process, child PID number to child process, 0 {  check for available kernel resources;  get free proc table slot, unique PID number;  check that user not running too many processes;  mark child state "being created;"
  8. 8. algorithm fork copy data from parent proc table slot to new child slot; increment counts on current directory inode and changed root (if applicable); increment open file counts in file table; make copy of parent context (u area, text, data, stack) in memory;
  9. 9. algorithm fork push dummy system level context layer onto child system level context;  dummy context contains data allowing child process to recognize itself, and start running from here when scheduled;
  10. 10. algorithm fork  if (executing process is parent process)  {  change child state to "ready to run;"  return (child ID); /* from system to user */  }  else /* executing process is the child process */  {  initialize u area timing fields;  return @); /• to user •/  } }
  11. 11. Checks before forking Resources to complete the fork successfully. On a swapping system,  it needs space either in memory or on disk to hold the child process; on a paging system,  it has to allocate memory for auxiliary tables such as page tables. If the resources are unavailable,  the fork call fails.
  12. 12. Checks continued.... The kernel finds a slot in the process table  to start constructing the context of the child process  User does not have too many processes running It also picks a unique ID number for the new process,  one greater than the most recently assigned ID
  13. 13. Process Limits (configurable) limit on the number of processes a user can simultaneously execute Ordinary users cannot create a process that would occupy the last remaining slot in the process table,  Because this could cause a deadlock
  14. 14. Super user Limits A superuser can execute as many processes as it likes, bounded by the  size of the process table, superuser process can occupy the last available slot in the process table
  15. 15. Inheritance Various fields are copied from the parent to the child  the child "inherits" the parent process real and effective user ID numbers  the parent process group,  the child process resides in the current directory of the parent process  the child process inherits the chroot changes and increments its inode reference count  Access rights to files opened by parent
  16. 16. user-level context of the child process It allocates memory for the child process  u area,  regions,  auxiliary page tables, duplicates every region in the parent process  using algorithm dupreg and attaches every region to the child process  using algorithm attachreg
  17. 17. Dynamic portion The kernel copies the parent context layer 1, containing  the user saved register context  the kernel stack frame The kernel then creates a dummy context layer(2)  containing the saved register context for context layer (1) It sets the program counter and other registers in the saved register context so it can be restored even though it has never been executed
  18. 18. Child process is ready !! When the child context is ready, The parent completes its part of fork by  Child state to "ready to run (in memory)"  Returning the child process ID to the user The child process appears to have awakened after awaiting a resource
  19. 19. Any Questions ?
  20. 20. Thank You !!