* Copyright (c) 1982, 1986 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
* @(#)kern_acct.c 7.2 (Berkeley) %G%
* SHOULD REPLACE THIS WITH A DRIVER THAT CAN BE READ TO SIMPLIFY.
* Perform process accounting functions.
register struct inode
*ip
;
} *uap
= (struct a
*)u
.u_ap
;
register struct nameidata
*ndp
= &u
.u_nd
;
ndp
->ni_nameiop
= LOOKUP
| FOLLOW
;
ndp
->ni_segflg
= UIO_USERSPACE
;
ndp
->ni_dirp
= uap
->fname
;
if ((ip
->i_mode
&IFMT
) != IFREG
) {
if (ip
->i_fs
->fs_ronly
) {
if (acctp
&& (acctp
->i_number
!= ip
->i_number
||
acctp
->i_dev
!= ip
->i_dev
))
int acctsuspend
= 2; /* stop accounting when < 2% free space left */
int acctresume
= 4; /* resume when free space risen to > 4% */
* On exit, write a record on the accounting file.
register struct inode
*ip
;
register struct rusage
*ru
;
register struct acct
*ap
= &acctbuf
;
if (freespace(fs
, fs
->fs_minfree
+ acctresume
) > 0) {
printf("Accounting resumed\n");
if ((ip
= acctp
) == NULL
)
if (freespace(fs
, fs
->fs_minfree
+ acctsuspend
) <= 0) {
printf("Accounting suspended\n");
for (i
= 0; i
< sizeof (ap
->ac_comm
); i
++)
ap
->ac_comm
[i
] = u
.u_comm
[i
];
ap
->ac_utime
= compress(ru
->ru_utime
.tv_sec
, ru
->ru_utime
.tv_usec
);
ap
->ac_stime
= compress(ru
->ru_stime
.tv_sec
, ru
->ru_stime
.tv_usec
);
timevalsub(&t
, &u
.u_start
);
ap
->ac_etime
= compress(t
.tv_sec
, t
.tv_usec
);
ap
->ac_btime
= u
.u_start
.tv_sec
;
timevaladd(&t
, &ru
->ru_utime
);
if (i
= t
.tv_sec
* hz
+ t
.tv_usec
/ tick
)
ap
->ac_mem
= (ru
->ru_ixrss
+ru
->ru_idrss
+ru
->ru_isrss
) / i
;
ap
->ac_mem
>>= CLSIZELOG2
;
ap
->ac_io
= compress(ru
->ru_inblock
+ ru
->ru_oublock
, (long)0);
ap
->ac_flag
= u
.u_acflag
;
rdwri(UIO_WRITE
, ip
, (caddr_t
)ap
, sizeof (acctbuf
), siz
,
* Produce a pseudo-floating point representation
* with 3 bits base-8 exponent, 13 bits fraction.
register exp
= 0, round
= 0;
t
= t
* AHZ
; /* compiler will convert only this format to a shift */
t
+= ut
/ (1000000 / AHZ
);