From ce00b8b1e2bd04f9785684ad67a65de19f082cb7 Mon Sep 17 00:00:00 2001 From: jacklag <73839788+jacklag@users.noreply.github.com> Date: Mon, 9 Jan 2023 16:08:12 +0000 Subject: [PATCH] select correct /proc/#/status file fields on BSD systems --- src/shellingham/posix/proc.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/shellingham/posix/proc.py b/src/shellingham/posix/proc.py index 14cf9da..9dcc45b 100644 --- a/src/shellingham/posix/proc.py +++ b/src/shellingham/posix/proc.py @@ -5,9 +5,18 @@ from ._core import Process - -STAT_PPID = 3 -STAT_TTY = 6 +if os.uname().sysname.lower() in ('freebsd', 'netbsd', 'dragonfly'): + # /proc/#/status fields on BSD systems + # FreeBSD: https://www.freebsd.org/cgi/man.cgi?query=procfs&apropos=0&sektion=0&manpath=FreeBSD+13.1-RELEASE&arch=default&format=html + # NetBSD: https://man.netbsd.org/NetBSD-9.3-STABLE/mount_procfs.8 + # DragonFlyBSD: https://www.dragonflybsd.org/cgi/web-man?command=procfs + STAT_PPID = 2 + STAT_TTY = 5 +else: + # /proc/#/status fields on linux systems + # see https://docs.kernel.org/filesystems/proc.html + STAT_PPID = 3 + STAT_TTY = 6 STAT_PATTERN = re.compile(r"\(.+\)|\S+")