January 18, 2006
Coverage: [USP] Chapter 3
Process Identification
- process id, parent process id
- getpid and getppid
- real vs. effective user and group ids
- getuid, getgid,
geteuid, getegid
- cast results of these functions to long
- output of ps command provides many of these details,
including process state (see below)
- some options -a, -A, -l, and -o
Process State
- new, ready, running, blocked, and done states; and transitions between
them
Overview of Process Creation System Calls
(courtesy [ATT])
Fork
- system call used for process creation in UNIX
- caller becomes parent and newly created process is child
- processes are the same except for the process id
- child inherits many attributes of its parent,
e.g., environment, privileges, open files and devices
- returns 0 to the child and the child pid to the parent
- execution proceeds after the call to fork in each process image
- parent code and child code
- effect of concurrency
- sleep function, takes seconds to block as an int,
e.g., sleep(30)
Graphic Depiction of Fork
(courtesy [ATT])
Fork Exercises
- creating a chain of n processes
- creating a fan of n processes
Wait
- causes the parent (caller) to block until child's
status becomes available (typically after it finishes) or
until the caller receives a signal
- wait vs. waitpid
- r_wait
- how can a process wait for all of its children?
- functions for testing the return status of a child
Graphic Depiction of Wait
(courtesy [ATT])
Exec
- this family of functions which provide support for swapping
out the image of the calling process and replacing it
with a new image
- traditional fork-exec sequences
- child swaps in the new image (with exec)
- parents continues to execute original code
- six variations differ in the way command-line arguments
and the environment are passed, and in relative and
absolute paths to executable
- use execl (execl, execlp, execle)
functions when you know the number of command-line arguments at
compile time
- use execv (execv, execvp, execve)
functions when you do not know the number of command-line arguments until
run time
- use an argument array to pass command-line arguments (e.g.,
such as one produced with makeargv)
- how can the combined use of exec and makeargv
cause a memory leak?
- trick to remember which call does what
Graphic Depiction of Exec
(courtesy [ATT])
How can the use of systems calls produce slower code?
Interesting Questions
(courtesy William Kimball)
- why go through the overhead of copying process image if you
are simply going to replace it with another image?
- does system address this?
- can the l family of exec calls be used
when the number of arguments are unknown until run-time?
Other Things to Know
- critical sections
- mutual exclusion
- locking mechanisms
Background Processes
- mozilla&
- daemons
- run indefinitely
- e.g., pageout, printer
References
[ATT] UNIX System Calls and Libraries -- Part 1, Version 2.1.1, AT&T, 1990.