diff --git a/src/sysdep.c b/src/sysdep.c index 2f79a71..5cefc75 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -3200,6 +3200,45 @@ list_system_processes () return proclist; } +#elif defined (BSD_SYSTEM) +#include + +Lisp_Object +list_system_processes () +{ + struct gcpro gcpro1; + Lisp_Object proclist = Qnil; + struct kinfo_proc * procinfo; + const int name[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0}; + size_t length; + int err; + int i; + EMACS_INT pid; + + GCPRO1 (proclist); + err = sysctl((int *)name, 4, NULL, &length, NULL, 0); + if (err == 0 && length > 0) + { + procinfo = malloc (length); + if (procinfo != NULL) + { + err = sysctl((int *)name, 4, procinfo, &length, NULL, 0); + if (err == 0 && length > 0) + { + for (i=0; i < (length/sizeof(*procinfo)); i++) + { + pid = procinfo[i].kp_proc.p_pid; + proclist = Fcons (make_fixnum_or_float(pid), proclist); + } + } + free(procinfo); + } + } + UNGCPRO; + + return proclist; +} + /* The WINDOWSNT implementation is in w32.c. The MSDOS implementation is in dosfns.c. */ #elif !defined (WINDOWSNT) && !defined (MSDOS)