MCPcopy Create free account
hub / github.com/F-Stack/f-stack / acct_process

Function acct_process

freebsd/kern/kern_acct.c:347–451  ·  view source on GitHub ↗

* 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.) */

Source from the content-addressed store, hash-verified

345 * "acct.h" header file.)
346 */
347int
348acct_process(struct thread *td)
349{
350 struct acctv3 acct;
351 struct timeval ut, st, tmp;
352 struct plimit *oldlim;
353 struct proc *p;
354 struct rusage ru;
355 int t, ret;
356
357 /*
358 * Lockless check of accounting condition before doing the hard
359 * work.
360 */
361 if (acct_vp == NULL || acct_suspended)
362 return (0);
363
364 sx_slock(&acct_sx);
365
366 /*
367 * If accounting isn't enabled, don't bother. Have to check again
368 * once we own the lock in case we raced with disabling of accounting
369 * by another thread.
370 */
371 if (acct_vp == NULL || acct_suspended) {
372 sx_sunlock(&acct_sx);
373 return (0);
374 }
375
376 p = td->td_proc;
377
378 /*
379 * Get process accounting information.
380 */
381
382 sx_slock(&proctree_lock);
383 PROC_LOCK(p);
384
385 /* (1) The terminal from which the process was started */
386 if ((p->p_flag & P_CONTROLT) && p->p_pgrp->pg_session->s_ttyp)
387 acct.ac_tty = tty_udev(p->p_pgrp->pg_session->s_ttyp);
388 else
389 acct.ac_tty = NODEV;
390 sx_sunlock(&proctree_lock);
391
392 /* (2) The name of the command that ran */
393 bcopy(p->p_comm, acct.ac_comm, sizeof acct.ac_comm);
394
395 /* (3) The amount of user and system time that was used */
396 rufetchcalc(p, &ru, &ut, &st);
397 acct.ac_utime = encode_timeval(ut);
398 acct.ac_stime = encode_timeval(st);
399
400 /* (4) The elapsed time the command ran (and its starting time) */
401 getboottime(&tmp);
402 timevaladd(&tmp, &p->p_stats->p_start);
403 acct.ac_btime = tmp.tv_sec;
404 microuptime(&tmp);

Callers 1

exit1Function · 0.85

Calls 11

rufetchcalcFunction · 0.85
encode_timevalFunction · 0.85
getboottimeFunction · 0.85
microuptimeFunction · 0.85
encode_longFunction · 0.85
tty_udevFunction · 0.70
timevaladdFunction · 0.70
timevalsubFunction · 0.70
lim_holdFunction · 0.70
lim_freeFunction · 0.70
vn_rdwrFunction · 0.70

Tested by

no test coverage detected