Code Reference

libproc

Low-level bindings to libproc.dylib.

This module exposes only one function, proc_info(). Please refer to the documentation directory for explanation on how to use it correctly.

Note

That the only low-level binding is the proc_info() function itself. All of the other functions are pure-python wrappers around it that don’t require the caller to handle ctypes.

libproc.proc_info(callnum, pid, flavor, arg, buffer, buf_size)

The proc_info() low-level system call.

The python3-style signature of proc_info() is:

__proc_info(
     callnum: ctypes.c_int,
     pid: ctypes.c_int,
     flavor: ctypes.c_int,
     arg: ctypes.c_uint64,
     buffer: ctypes.c_void_p,
     buf_size: ctypes.c_int
) -> ctypes.c_int

There is also an error checker that raises OSError if the underlying call fails. This is easy to do if the buffer is handled incorrectly or callnum or pid are invalid.

This function uses multiplexing on callnum to invoke distinct kernel functions. Please look at the PROC_CALLNUM_xxx family of constants for details.

libproc.PROC_CALLNUM_LISTPIDS = 1

Value of __proc_info(callnum, ...), returns a list of PIDs.

libproc.PROC_CALLNUM_PIDINFO = 2

Undocumented.

libproc.PROC_CALLNUM_PIDFDINFO = 3

Undocumented.

libproc.PROC_CALLNUM_KERNMSGBUF = 4

Undocumented.

libproc.PROC_CALLNUM_SETCONTROL = 5

Undocumented.

libproc.PROC_CALLNUM_PIDFILEPORTINFO = 6

Undocumented.

libproc.PROC_ALL_PIDS = 1

When called with callnum 1, return all processes

libproc.PROC_PGRP_ONLY = 2

When called with callnum 1, return all processes in a given group

libproc.PROC_TTY_ONLY = 3

When called with callnum 1, return all processes attached to a given tty

libproc.PROC_UID_ONLY = 4

When called with callnum 1, return all processes with the given UID

libproc.PROC_RUID_ONLY = 5

When called with callnum 1, return all processes with the given RUID

libproc.PROC_PPID_ONLY = 6

When called with callnum 1, return all processes with the given PPID

libproc.get_all_pids()[source]

Get a list of all process IDs.

Returns:A list of all the process IDs on this system.
Raises OSError:If the underlying system call fails.
libproc.get_pids_for_uid(uid)[source]

Get a list of PIDs (process IDs) with the specific user ID.

Parameters:uid – The UID to look for.
Returns:A list of matching PIDs.
Raises OSError:If the underlying system call fails.
libproc.get_pids_for_ruid(ruid)[source]

Get a list of PIDs (process IDs) with the specific real user ID.

Parameters:ruid – The RUID to look for.
Returns:A list of matching PIDs.
Raises OSError:If the underlying system call fails.
libproc.get_pids_for_ppid(ppid)[source]

Get a list of PIDs (process IDs) with the specific parent PID.

Parameters:ppid – The parent process ID to look for.
Returns:A list of matching PIDs.
Raises OSError:If the underlying system call fails.
libproc.get_pids_for_pgrp(pgrp)[source]

Get a list of PIDs (process IDs) with the specific process group.

Parameters:pgrp – The process group ID to look for.
Returns:A list of matching PIDs.
Raises OSError:If the underlying system call fails.
libproc.get_pids_for_tty(tty)[source]

Get a list of PIDs (process IDs) with the specific TTY.

Parameters:tty – The TTY to look for.
Returns:A list of matching PIDs.
Raises OSError:If the underlying system call fails.