The Linux Programming Interface

(nextflipdebug5) #1
Process Creation and Program Execution in More Detail 597

printf("command flags term. user "
"start time CPU elapsed\n");
printf(" status "
" time time\n");


while ((numRead = read(acctFile, &ac, sizeof(struct acct))) > 0) {
if (numRead != sizeof(struct acct))
fatal("partial read");


printf("%-8.8s ", ac.ac_comm);


printf("%c", (ac.ac_flag & AFORK)? 'F' : '-') ;
printf("%c", (ac.ac_flag & ASU)? 'S' : '-') ;
printf("%c", (ac.ac_flag & AXSIG)? 'X' : '-') ;
printf("%c", (ac.ac_flag & ACORE)? 'C' : '-') ;


#ifdef linux
printf(" %#6lx ", (unsigned long) ac.ac_exitcode);
#else / Many other implementations provide ac_stat instead /
printf(" %#6lx ", (unsigned long) ac.ac_stat);
#endif


s = userNameFromId(ac.ac_uid);
printf("%-8.8s ", (s == NULL)? "???" : s);


t = ac.ac_btime;
loc = localtime(&t);
if (loc == NULL) {
printf("???Unknown time??? ");
} else {
strftime(timeBuf, TIME_BUF_SIZE, "%Y-%m-%d %T ", loc);
printf("%s ", timeBuf);
}


printf("%5.2f %7.2f ", (double) (comptToLL(ac.ac_utime) +
comptToLL(ac.ac_stime)) / sysconf(_SC_CLK_TCK),
(double) comptToLL(ac.ac_etime) / sysconf(_SC_CLK_TCK));
printf("\n");
}


if (numRead == -1)
errExit("read");


exit(EXIT_SUCCESS);
}
–––––––––––––––––––––––––––––––––––––––––––––––––––––– procexec/acct_view.c


Process accounting Version 3 file format


Starting with kernel 2.6.8, Linux introduced an optional alternative version of the
process accounting file that addresses some limitations of the traditional accounting
file. To use this alternative version, known as Version 3, the CONFIG_BSD_PROCESS_ACCT_V3
kernel configuration option must be enabled before building the kernel.

Free download pdf