ECSE 427 Lecture Notes - Lecture 3: File Descriptor, Anonymous Pipe, Child Process
ECSE 427 – Tutorial #3 Notes
Alex Hale
Fork
- split one entity into multiple similar (nearly identical) entities
- to differentiate the parent and the child after the fork:
o in the parent process, fork() returns the child process ID
o in the child process, fork() returns 0
- example: two fork() calls in one program results in four
processes being created
- variables created before the fork() call get copied into the
child
- changes to those variables after the fork() do not reflect in the
other process
- the order of execution of the parent and child process is not defined – it can be either one
o if we want to, we can make the parent wait for the child to complete before executing –
see waitpid()
WaitPID
Argument 1 – pid_t pid
- the parent can choose to wait for a particular child to complete
o pid is the PID of that child
Argument 2 – int *stat_loc
- the value pointed to indicates how the process terminated: coredump, interrupted, or signal
find more resources at oneclass.com
find more resources at oneclass.com