Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

Section 8.14 Process Accounting 271


FreeBSD Linux Mac OS X Solaris
ac_flag Description 8.0 3.2.0 10.6.8 10

AFORK process is the result offork,but never calledexec ••••
ASU process used superuser privileges •••
ACORE process dumped core•••
AXSIG process was killed by a signal •••
AEXPND expanded accounting entry •
ANVER new recordformat •

Figure 8.26Values forac_flagfrom accounting record

execs B, then Bexecs C, and Cexits—only a single accounting record is written.
The command name in the recordcorresponds to program C, but the CPU times, for
example, arethe sum for programs A, B, and C.

Example


To have some accounting data to examine, we’ll create a test program to implement the
diagram shown in Figure8.27.

sleep( 2 )
exit( 2 )
sleep( 4 )
abort()

sleep( 8 )
exit( 0 )
sleep( 6 )
kill()

parent
first child
second child
thirdchild
fourth child

/bin/dd

fork
fork
fork
fork

execl

Figure 8.27 Process structurefor accounting example

The source for the test program is shown in Figure8.28. It callsforkfour times. Each
child does something different and then terminates.
#include "apue.h"
int
main(void)
{
pid_t pid;
if ((pid = fork()) < 0)
err_sys("fork error");
Free download pdf