26 MONITORING CHILD PROCESSES 541 26.1
Waiting on a Child Process ........................................................................................ 541
26.1.1
The
wait()
System Call........................................................................... 541
26.1.2
The
waitpid()
System Call ...................................................................... 544
26.1.3
The Wait Status Value ........................................................................... 545
26.1.4
Process Termination from a Signal Handler .............................................. 549
26.1.5
The
waitid()
System Call ........................................................................ 550
26.1.6
The
wait3()
and
wait4()
System Calls...................................................... 552
26.2
Orphans and Zombies ............................................................................................... 553
26.3
The SIGCHLD Signal .................................................................................................... 555
26.3.1
Establishing a Handler for SIGCHLD .......................................................... 555
26.3.2
Delivery of SIGCHLD for Stopped Children ................................................. 559
26.3.3
Ignoring Dead Child Processes ............................................................... 559
26.4
Summary.................................................................................................................. 561
26.5
Exercises .................................................................................................................. 562
27 PROGRAM EXECUTION 563 27.1
Executing a New Program:
execve()
............................................................................. 563
27.2
The
exec()
Library Functions......................................................................................... 567
27.2.1
The PATH Environment Variable ............................................................... 568
27.2.2
Specifying Program Arguments as a List................................................... 570
27.2.3
Passing the Caller’s Environment to the New Program ............................... 570
27.2.4
Executing a File Referred to by a Descriptor:
fexecve()
................................ 571
27.3
Interpreter Scripts ...................................................................................................... 572
27.4
File Descriptors and
exec()
.......................................................................................... 575
27.5
Signals and
exec()
..................................................................................................... 578
27.6
Executing a Shell Command:
system()
.......................................................................... 579
27.7
Implementing
system()
................................................................................................ 582
27.8
Summary.................................................................................................................. 588
27.9
Exercises .................................................................................................................. 589