1 / 15

Chapter 2 Process management —— Process Creation&Execution

Chapter 2 Process management —— Process Creation&Execution. Outline. Introduction to Process Creation & Execution Process Creation Process Execution. Process Creation. A kernel newproc() function  PID0-PID4 fork(2). Process Creation & Execution. Traditional UNIX fork/exec model

Download Presentation

Chapter 2 Process management —— Process Creation&Execution

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 2 Process management—— Process Creation&Execution

  2. Outline • Introduction to Process Creation & Execution • Process Creation • Process Execution

  3. Process Creation • A kernel newproc() function  PID0-PID4 • fork(2)

  4. Process Creation & Execution • Traditional UNIX fork/exec model • – fork(2) - replicate the entire process, including all threads • – fork1(2) - replicate the process, only the calling thread • – vfork(2) - replicate the process, but do not dup the address space • The new child borrows the parents address space, until exec() • Pseudocode main(int argc, char *argv[]) { pid_t pid; pid = fork(); if (pid == 0) /* in the child */ exec(); else if (pid > 0) /* in the parent */ wait(); else fork failed }

  5. Outline • Introduction to Process Creation & Execution • Process Creation • Process Execution

  6. fork(2) • A common process creation system call • The fork(2) system call creates a new process with a PID • Return value • 0 to the child process • PID of the child to the parent process • fork(2) duplicates the entire parent process, including all the threads and LWPs

  7. fork(2) in Solaris 10 • Solaris 10 unified the process model • libthread merged with libc • threaded and non-threaded processes look the same • fork(2) now replicates only the calling thread • Previously, fork1(2) needed to be called to do this • Linking with -lpthread in previous releases also resulted in fork1(2) behaviour • Linking with -lthread resulted in replicated-all fork(2) behaviour • forkall(2) added for applications that require a fork to replicate all the threads in the process

  8. fork1(2) • A variant of fork(2) • Only the thread that issues the fork1(2) call and its associated support structures are replicated • reduces the overhead of replicating • useful for some multithreaded programs

  9. vfork(2) • a “virtual memory efficient” version of fork • child process “borrowing” the address space of the parent, rather than duplicating • The child must not change any state while executing in the parent’s address space • can improve application efficiency

  10. Outline • Introduction to Process Creation & Execution • Process Creation • Process Execution

  11. exec(2) • Load a new process image • Most fork(2) calls are followed by an exec(2) • exec – execute a new file • exec overlays the process image with a new process constructed from the binary file passed as an arg to exec(2) • The exec'd process inherits much of the caller's state: • nice value, scheduling class, priority, PID, PPID, GID, task ID, project ID, session membership, real UID & GID, current working directory, resource limits, processor binding, times, etc, ...

  12. exec Flow

  13. exec Flow to Object-Specific Routine

  14. Reference • Jim Mauro, Richard McDougall, Solaris Internals-Core Kernel Components, Sun Microsystems Press, 2000 • Sun,Multithreading in the Solaris Operating Environment, A Technical White Paper,2002 • Solaris internals and performance management, Richard McDougall, 2002

  15. End • Last.first@Sun.COM

More Related