acct(2)

๐Ÿ’– acct(2) โ€” the process accounting switch ๐Ÿ’–

okay bestie, so this is a page from the System Calls Manual (yes, section 2, we're in kernel-land, it's giving syscall energy โœจ) and honestly? it's such a lil guy with such big power. let's get into it ๐Ÿซถ


๐ŸŒธ NAME ๐ŸŒธ

acct โ€” switch process accounting on or off

like... a literal on/off switch for the receipt-printer of your system. bestie is a toggler ๐Ÿ’…


๐Ÿ“š LIBRARY ๐Ÿ“š

Standard C library (libc, -lc)

so you already have it, no extra install, no extra drama ๐ŸŽ€


โœจ SYNOPSIS โœจ

#include <unistd.h>

int acct(const char *_Nullable path);

๐Ÿฆ‹ Feature Test Macro Requirements for glibc ๐Ÿฆ‹

(peep feature_test_macros(7) if you need the lore, iykyk)

acct():

  • Since glibc 2.21:
    • _DEFAULT_SOURCE
  • In glibc 2.19 and 2.20:
    • _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
  • Up to and including glibc 2.19:
    • _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)

so basically, depending on which glibc era you're living in, you gotta define the right macro or this thing ghosts you ๐Ÿ˜ญ define responsibly!


๐Ÿ’œ DESCRIPTION ๐Ÿ’œ

The acct() system call enables or disables process accounting. periodt.

Here's the tea โ˜• โ€” pass it the pathname of an existing file as its argument and accounting gets turned on, and then records for every single terminating process get appended to that file as each one terminates. like a lil diary where every process writes its final entry before it exits. so sentimental honestly ๐Ÿฅน

And if you pass NULL as the argument? accounting gets turned off. that's it, that's the whole switch. iconic behaviour, no notes ๐Ÿ‘‘


๐Ÿ”ฅ RETURN VALUE ๐Ÿ”ฅ

  • On success: zero is returned. slay. โœ…
  • On error: -1 is returned, and errno is set to tell you what went wrong. rude but informative ๐Ÿ’€

๐Ÿ˜ญ ERRORS ๐Ÿ˜ญ

okay so this is the part where things can go sideways. every one of these is a real mood, let's go through them:

  • EACCES โ€” Write permission is denied for the specified file, or search permission is denied for one of the directories in the path prefix of path (peep path_resolution(7) for that whole saga), or path is not a regular file.
  • EFAULT โ€” path points outside your accessible address space. bestie is pointing at โœจthe voidโœจ outside your memory.
  • EIO โ€” Error writing to the file path. the write just... didn't write.
  • EISDIR โ€” path is a directory. bestie, that's a folder, not a file, that's not it ๐Ÿ™ˆ
  • ELOOP โ€” Too many symbolic links were encountered in resolving path. symlink rabbit hole, we've all been there ๐Ÿ•ณ๏ธ
  • ENAMETOOLONG โ€” path was too long. it's giving novel, not pathname ๐Ÿ“–
  • ENFILE โ€” The system-wide limit on the total number of open files has been reached. the whole system ran out of file slots, not just you.
  • ENOENT โ€” The specified path does not exist. it's not real, it was never real ๐Ÿ’€
  • ENOMEM โ€” Out of memory. no thoughts, head empty, RAM empty.
  • ENOSYS โ€” BSD process accounting has not been enabled when the operating system kernel was compiled. the kernel config parameter that controls this feature is CONFIG_BSD_PROCESS_ACCT. so if your kernel wasn't built with it, this syscall is lowkey just a rumour ๐ŸŒซ๏ธ
  • ENOTDIR โ€” A component used as a directory in path is not in fact a directory. it was pretending. fraud alert ๐Ÿšจ
  • EPERM โ€” The calling process has insufficient privilege to enable process accounting. on Linux, the CAP_SYS_PACCT capability is required. so no cap (capability), no CAP_SYS_PACCT ๐Ÿ”‘
  • EROFS โ€” path refers to a file on a read-only filesystem. you cannot write to the read-only, that's literally the whole point ๐ŸงŠ
  • EUSERS โ€” There are no more free file structures or we ran out of memory. two-for-one chaos.
fr fr read these, don't just skim. EPERM is the one that gets people โ€” if you don't have CAP_SYS_PACCT, it's over before it started ๐Ÿ˜”

๐ŸŽ€ STANDARDS ๐ŸŽ€

None. nope, not standardized, no committee signing off on this one, it's just out here living its life ๐ŸŒˆ


โญ HISTORY โญ

  • SVr4
  • 4.3BSD

vintage! a classic! we stan an elder ๐Ÿ“


๐ŸŒŸ NOTES ๐ŸŒŸ

  • No accounting is produced for programs running when a system crash occurs. and in particular, nonterminating processes are never accounted for. so if a process never ends, it never gets a diary entry. it simply persists. main character energy, honestly, refusing to have an exit ๐Ÿ’…
  • The structure of the records written to the accounting file is described in acct(5). go peep that page for the record layout lore ๐Ÿ““

๐Ÿ’ซ SEE ALSO ๐Ÿ’ซ


okay bestie that's the whole page!! you now know how to flip process accounting on and off, every reason it might scream at you, and the fact that crashed systems just lose the receipts ๐Ÿ˜ญ go forth and toggle responsibly ๐Ÿซถโœจ

this lil rewrite was brought to you by Linux man-pages 6.20, dated 2025-05-17 โ€” mwah, love u, bye ๐Ÿ’–๐ŸŽ€๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: GPL-2.0-or-later
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms