150 likes | 293 Views
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
E N D
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 • – 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 }
Outline • Introduction to Process Creation & Execution • Process Creation • Process Execution
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
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
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
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
Outline • Introduction to Process Creation & Execution • Process Creation • Process Execution
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, ...
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
End • Last.first@Sun.COM