1*5b125427Schristos.\" $NetBSD: acct.5,v 1.12 2024/08/05 13:04:14 christos Exp $ 2b5930afcSjtc.\" 3b5930afcSjtc.\" Copyright (c) 1991, 1993 4b5930afcSjtc.\" The Regents of the University of California. All rights reserved. 561f28255Scgd.\" 661f28255Scgd.\" Redistribution and use in source and binary forms, with or without 761f28255Scgd.\" modification, are permitted provided that the following conditions 861f28255Scgd.\" are met: 961f28255Scgd.\" 1. Redistributions of source code must retain the above copyright 1061f28255Scgd.\" notice, this list of conditions and the following disclaimer. 1161f28255Scgd.\" 2. Redistributions in binary form must reproduce the above copyright 1261f28255Scgd.\" notice, this list of conditions and the following disclaimer in the 1361f28255Scgd.\" documentation and/or other materials provided with the distribution. 14075022b3Sagc.\" 3. Neither the name of the University nor the names of its contributors 1561f28255Scgd.\" may be used to endorse or promote products derived from this software 1661f28255Scgd.\" without specific prior written permission. 1761f28255Scgd.\" 1861f28255Scgd.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1961f28255Scgd.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2061f28255Scgd.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2161f28255Scgd.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2261f28255Scgd.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2361f28255Scgd.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2461f28255Scgd.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2561f28255Scgd.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2661f28255Scgd.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2761f28255Scgd.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2861f28255Scgd.\" SUCH DAMAGE. 2961f28255Scgd.\" 30b5930afcSjtc.\" @(#)acct.5 8.1 (Berkeley) 6/5/93 3161f28255Scgd.\" 32*5b125427Schristos.Dd August 5, 2024 3361f28255Scgd.Dt ACCT 5 3461f28255Scgd.Os 3561f28255Scgd.Sh NAME 3661f28255Scgd.Nm acct 3761f28255Scgd.Nd execution accounting file 3861f28255Scgd.Sh SYNOPSIS 39472351e1Swiz.In sys/acct.h 4061f28255Scgd.Sh DESCRIPTION 4161f28255ScgdThe kernel maintains the following 4261f28255Scgd.Fa acct 4361f28255Scgdinformation structure for all 4461f28255Scgdprocesses. If a process terminates, and accounting is enabled, 4561f28255Scgdthe kernel calls the 46*5b125427Schristos.Xr acct_process 9 4761f28255Scgdfunction call to prepare and append the record 4861f28255Scgdto the accounting file. 4961f28255Scgd.Bd -literal 5061f28255Scgd/* 5161f28255Scgd * Accounting structures; these use a comp_t type which is a 3 bits base 8 5261f28255Scgd * exponent, 13 bit fraction ``floating point'' number. Units are 1/AHZ 5361f28255Scgd * seconds. 5461f28255Scgd */ 559b91a11cSchristostypedef uint16_t comp_t; 5661f28255Scgd 5761f28255Scgdstruct acct { 589b91a11cSchristos char ac_comm[16]; /* name of command */ 5961f28255Scgd comp_t ac_utime; /* user time */ 6061f28255Scgd comp_t ac_stime; /* system time */ 6161f28255Scgd comp_t ac_etime; /* elapsed time */ 6261f28255Scgd time_t ac_btime; /* starting time */ 6361f28255Scgd uid_t ac_uid; /* user id */ 6461f28255Scgd gid_t ac_gid; /* group id */ 659b91a11cSchristos uint16_t ac_mem; /* memory usage average */ 6661f28255Scgd comp_t ac_io; /* count of IO blocks */ 6761f28255Scgd dev_t ac_tty; /* controlling tty */ 689b91a11cSchristos#define AFORK 0x01 /* fork'd but not exec'd */ 6961f28255Scgd#define ASU 0x02 /* used super-user permissions */ 7061f28255Scgd#define ACOMPAT 0x04 /* used compatibility mode */ 7161f28255Scgd#define ACORE 0x08 /* dumped core */ 7261f28255Scgd#define AXSIG 0x10 /* killed by a signal */ 739b91a11cSchristos uint8_t ac_flag; /* accounting flags */ 7461f28255Scgd}; 7561f28255Scgd 7661f28255Scgd/* 7761f28255Scgd * 1/AHZ is the granularity of the data encoded in the comp_t fields. 7861f28255Scgd * This is not necessarily equal to hz. 7961f28255Scgd */ 8061f28255Scgd#define AHZ 64 8161f28255Scgd 829b91a11cSchristos#ifdef _KERNEL 839b91a11cSchristosvoid acct_init(void); 849b91a11cSchristosint acct_process(struct lwp *); 859b91a11cSchristosendif 8661f28255Scgd.Ed 8761f28255Scgd.Pp 8861f28255ScgdIf a terminated process was created by an 8961f28255Scgd.Xr execve 2 , 9061f28255Scgdthe name of the executed file (at most ten characters of it) 9161f28255Scgdis saved in the field 9261f28255Scgd.Fa ac_comm 9361f28255Scgdand its status is saved by setting one of more of the following flags in 9461f28255Scgd.Fa ac_flag : 9561f28255Scgd.Dv AFORK , 96dd08f8bcSchristos.Dv ACORE , 9761f28255Scgdand 98dd08f8bcSchristos.Dv AXSIG . 99c7a999e1Sad.Pp 100c7a999e1SadThe 101c7a999e1Sad.Dv ASU 102dd08f8bcSchristosflag is not recorded anymore because with the switch to 103dd08f8bcSchristos.Xr kauth 9 , 104dd08f8bcSchristosthe superuser model is optional and passing the affected process to every 105dd08f8bcSchristosauthorization call in order to record 106dd08f8bcSchristos.Dv ASU 107dd08f8bcSchristosin 108dd08f8bcSchristos.Fa p_acflag , 109dd08f8bcSchristoswould require many source changes and would not reflect reality because 110dd08f8bcSchristosthe authorization decision might not have been done based on the 111dd08f8bcSchristos.Xr secmodel_suser 9 112dd08f8bcSchristosmodel. 113dd08f8bcSchristos.Pp 114dd08f8bcSchristosThe 115c7a999e1Sad.Dv ACOMPAT 116dd08f8bcSchristosflag was never recorded in 117dd08f8bcSchristos.Nx ; 118dd08f8bcSchristoswe could consider setting when the a process is running under emulation, 119dd08f8bcSchristosbut this is not currently done. 120dd08f8bcSchristos.Pp 121dd08f8bcSchristosBoth the 122dd08f8bcSchristos.Dv ASU 123dd08f8bcSchristosand the 124dd08f8bcSchristos.Dv ACOMPAT 125dd08f8bcSchristosflags are retained for source compatibility. 12661f28255Scgd.Sh SEE ALSO 127f4116626Sghudson.Xr lastcomm 1 , 1281863ec08Swiz.Xr acct 2 , 1291863ec08Swiz.Xr execve 2 , 1301863ec08Swiz.Xr accton 8 , 131*5b125427Schristos.Xr sa 8 , 132*5b125427Schristos.Xr acct_process 9 13361f28255Scgd.Sh HISTORY 13461f28255ScgdA 13561f28255Scgd.Nm 13661f28255Scgdfile format appeared in 13761f28255Scgd.At v7 . 138