FreeBSD/sys/kern/kern_acct.c
/*
 * Write out process accounting information, on process exit.
 * Data to be written out is specified in Leffler, et al.
 * and are enumerated below.  (They're also noted in the system
 * "acct.h" header file.)
 */
Write out process accounting information, on process exit.
Data to be written out is specified in Leffler, et al.
and are enumerated below.  (They're also noted in the system
"acct.h" header file.)
Write out process accounting information on process exit . Data to be written out is specified in Leffler et al . and are enumerated below . ( They ' re also noted in the system " acct . h " header file . )
int
acct_process(struct thread *td)
{
	struct acctv2 acct;
	struct timeval ut, st, tmp;
	struct plimit *oldlim;
	struct proc *p;
	struct rusage ru;
	int t, ret;
	if (acct_vp == NULL || acct_suspended)
		return (0);
	sx_slock(&acct_sx);
	if (acct_vp == NULL || acct_suspended) {
		sx_sunlock(&acct_sx);
		return (0);
	}
	p = td->td_proc;
	sx_slock(&proctree_lock);
	PROC_LOCK(p);
	if ((p->p_flag & P_CONTROLT) && p->p_pgrp->pg_session->s_ttyp)
		acct.ac_tty = tty_udev(p->p_pgrp->pg_session->s_ttyp);
	else
		acct.ac_tty = NODEV;
	sx_sunlock(&proctree_lock);
	bcopy(p->p_comm, acct.ac_comm, sizeof acct.ac_comm);
	rufetchcalc(p, &ru, &ut, &st);
	acct.ac_utime = encode_timeval(ut);
	acct.ac_stime = encode_timeval(st);
	tmp = boottime;
	timevaladd(&tmp, &p->p_stats->p_start);
	acct.ac_btime = tmp.tv_sec;
	microuptime(&tmp);
	timevalsub(&tmp, &p->p_stats->p_start);
	acct.ac_etime = encode_timeval(tmp);
	tmp = ut;
	timevaladd(&tmp, &st);
	t = tmp.tv_sec * hz + tmp.tv_usec / tick;
	if (t)
		acct.ac_mem = encode_long((ru.ru_ixrss + ru.ru_idrss +
		    + ru.ru_isrss) / t);
	else
		acct.ac_mem = 0;
	acct.ac_io = encode_long(ru.ru_inblock + ru.ru_oublock);
	acct.ac_uid = p->p_ucred->cr_ruid;
	acct.ac_gid = p->p_ucred->cr_rgid;
	acct.ac_flagx = p->p_acflag;
	acct.ac_flagx |= ANVER;
	acct.ac_zero = 0;
	acct.ac_version = 2;
	acct.ac_len = acct.ac_len2 = sizeof(acct);
	oldlim = p->p_limit;
	p->p_limit = lim_hold(acct_limit);
	PROC_UNLOCK(p);
	lim_free(oldlim);
	ret = vn_rdwr(UIO_WRITE, acct_vp, (caddr_t)&acct, sizeof (acct),
	    (off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, acct_cred, NOCRED,
	    NULL, td);
	sx_sunlock(&acct_sx);
	return (ret);
}
int acct_process ( struct thread * td ) { struct acctv2 acct ; struct timeval ut , st , tmp ; struct plimit * oldlim ; struct proc * p ; struct rusage ru ; int t , ret ; if ( acct_vp == NULL || acct_suspended ) return ( 0 ) ; sx_slock ( & acct_sx ) ; if ( acct_vp == NULL || acct_suspended ) { sx_sunlock ( & acct_sx ) ; return ( 0 ) ; } p = td -> td_proc ; sx_slock ( & proctree_lock ) ; PROC_LOCK ( p ) ; if ( ( p -> p_flag & P_CONTROLT ) && p -> p_pgrp -> pg_session -> s_ttyp ) acct . ac_tty = tty_udev ( p -> p_pgrp -> pg_session -> s_ttyp ) ; else acct . ac_tty = NODEV ; sx_sunlock ( & proctree_lock ) ; bcopy ( p -> p_comm , acct . ac_comm , sizeof acct . ac_comm ) ; rufetchcalc ( p , & ru , & ut , & st ) ; acct . ac_utime = encode_timeval ( ut ) ; acct . ac_stime = encode_timeval ( st ) ; tmp = boottime ; timevaladd ( & tmp , & p -> p_stats -> p_start ) ; acct . ac_btime = tmp . tv_sec ; microuptime ( & tmp ) ; timevalsub ( & tmp , & p -> p_stats -> p_start ) ; acct . ac_etime = encode_timeval ( tmp ) ; tmp = ut ; timevaladd ( & tmp , & st ) ; t = tmp . tv_sec * hz + tmp . tv_usec / tick ; if ( t ) acct . ac_mem = encode_long ( ( ru . ru_ixrss + ru . ru_idrss + + ru . ru_isrss ) / t ) ; else acct . ac_mem = 0 ; acct . ac_io = encode_long ( ru . ru_inblock + ru . ru_oublock ) ; acct . ac_uid = p -> p_ucred -> cr_ruid ; acct . ac_gid = p -> p_ucred -> cr_rgid ; acct . ac_flagx = p -> p_acflag ; acct . ac_flagx |= ANVER ; acct . ac_zero = 0 ; acct . ac_version = 2 ; acct . ac_len = acct . ac_len2 = sizeof ( acct ) ; oldlim = p -> p_limit ; p -> p_limit = lim_hold ( acct_limit ) ; PROC_UNLOCK ( p ) ; lim_free ( oldlim ) ; ret = vn_rdwr ( UIO_WRITE , acct_vp , ( caddr_t ) & acct , sizeof ( acct ) , ( off_t ) 0 , UIO_SYSSPACE , IO_APPEND | IO_UNIT , acct_cred , NOCRED , NULL , td ) ; sx_sunlock ( & acct_sx ) ; return ( ret ) ; }
Write out process accounting information, on process exit.
Write out process accounting information on process exit .
/*
	 * Lockless check of accounting condition before doing the hard
	 * work.
	 */ /*
	 * If accounting isn't enabled, don't bother.  Have to check again
	 * once we own the lock in case we raced with disabling of accounting
	 * by another thread.
	 */ /*
	 * Get process accounting information.
	 */ /* (1) The terminal from which the process was started */ /* (2) The name of the command that ran */ /* (3) The amount of user and system time that was used */ /* (4) The elapsed time the command ran (and its starting time) */ /* (5) The average amount of memory used */ /* Convert tmp (i.e. u + s) into hz units to match ru_i*. */ /* (6) The number of disk I/O operations done */ /* (7) The UID and GID of the process */ /* (8) The boolean flags that tell how the process terminated, etc. */ /* Setup ancillary structure fields. */ /*
	 * Eliminate rlimits (file size limit in particular).
	 */ /*
	 * Write the accounting information to the file.
	 */