Your name Your titile

Download Report

Transcript Your name Your titile

Chapter 2 Process management
—— Process Creation&Execution
Outline

Introduction to Process Creation &
Execution

Process Creation

Process Execution
2
Process Creation
A kernel
newproc() function  PID0-PID4
fork(2)
3
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
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
}
> The new child borrows the parents address
space, until exec()
4
Outline

Introduction to Process Creation &
Execution

Process Creation

Process Execution
5
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
6
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
7
fork1(2)
A variant
of fork(2)
Only
the thread that issues the fork1(2) call
and its associated support structures are
replicated
reduces
useful
the overhead of replicating
for some multithreaded programs
8
vfork(2)
a
“virtual memory efficient” version of fork
process “borrowing” the address
space of the parent, rather than duplicating
child
The
child must not change any state while
executing in the parent’s address space
can
improve application efficiency
9
Outline

Introduction to Process Creation &
Execution

Process Creation

Process Execution
10
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, ...
11
exec Flow
12
exec Flow to Object-Specific
Routine
13
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
14
End
• [email protected]
15