1

From https://unix.stackexchange.com/a/492346/674

Kernels such as Linux and the kernels of the BSDs provide four (relevant) pieces of information about a process, via files in /proc and sysctl():

  • its program image short name, a.k.a. the short name used for process accounting;
  • its argument strings, initialized by execve() and modifiable at runtime;
  • its environment strings, initialized by execve() and modifiable at runtime; and
  • the full pathname of its executable program image file.

Which file in /proc (and which arguments to sysctl()) provide each of the four pieces of information? Thanks.

Tim
  • 101,790

1 Answers1

5

On Linux:

  • its program image short name, a.k.a. the short name used for process accounting;
/proc/<pid>/comm
  • its argument strings, initialized by execve() and modifiable at runtime;
/proc/<pid>/cmdline
  • its environment strings, initialized by execve() and modifiable at runtime; and
/proc/<pid>/environ
  • the full pathname of its executable program image file.
/proc/<pid>/exe

(which is a symbolic link to the file).

Additional technical detail for these files can be found in man 5 proc.

On FreeBSD:

  • its program image short name, a.k.a. the short name used for process accounting;
  • sysctl() with CTL_KERN, KERN_PROC, and KERN_PROC_ALL/KERN_PROC_PROC OIDs.
  • Dumpable with sysctl -x kern.proc.all
  • One of the fields in /proc/PID/status.
  • (if compatibility is installed) one of the fields in /compat/linux/proc/PID/status.
  • its argument strings, initialized by execve() and modifiable at runtime;
  • sysctl() with CTL_KERN, KERN_PROC, and KERN_PROC_ARGS OIDs.
  • Also /proc/PID/cmdline.
  • (if compatibility is installed) /compat/linux/proc/PID/cmdline.
  • its environment strings, initialized by execve() and modifiable at runtime; and
  • sysctl() with CTL_KERN, KERN_PROC, and KERN_PROC_ENV OIDs.
  • (if compatibility is installed) /compat/linux/proc/PID/environ.
  • the full pathname of its executable program image file.
  • /proc/PID/file (which is a symbolic link to the file).
  • (if compatibility is installed) /compat/linux/proc/PID/exe.
sourcejedi
  • 50,249
Stephen Kitt
  • 434,908