I think a process count of 0 in procstat_getprocs() is not necessarily an error and this should not trigger a message to stderr.
The code below demonstrates the issue, assuming 1000 is not part of a process group. Tweak the value if necessary.
If procstat_getprocs() does not find any processes in the group, it returns 0 via the *count argument as expected, but also prints a warning to stderr using warnx():
kinfo_proc structure size mismatch (len = 0)
The warnx() call can be found in /usr/src/lib/libprocstat/libprocstat.c.
It seems to be that the action to be taken when count == 0 should be left to the caller.
int main(int argc,char *argv)
unsigned pgid = 1000,
struct procstat *proc_info;
struct kinfo_proc *proc_list;
// FILE *procstat_err;
proc_info = procstat_open_sysctl();
// Silence warnx()
// procstat_err = fopen("/dev/null", "w+");
proc_list = procstat_getprocs(proc_info, KERN_PROC_PGRP, pgid,
Another issue with this is that pid_count is not set to 0 when no matching processes are found. I think this would be good to do even if the case is considered an error.