GNU bug report logs - #5725
23.1.94; list_system_processes for BSD_SYSTEM (with patch)

Previous Next

Package: emacs;

Reported by: Leo <sdl.web <at> gmail.com>

Date: Mon, 15 Mar 2010 17:02:02 UTC

Severity: wishlist

Tags: patch

Done: Leo <sdl.web <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Leo <sdl.web <at> gmail.com>
To: 5725 <at> debbugs.gnu.org
Subject: bug#5725: 23.1.94; list_system_processes for BSD_SYSTEM (with patch)
Date: Mon, 15 Mar 2010 17:01:10 +0000
[Message part 1 (text/plain, inline)]
The included patch implements list_system_processes through sysctl.h
which I guess is available on all BSD systems. I have also implemented
process_attributes and will send it in after more testing.

[lsp.diff (text/x-patch, inline)]
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 <sys/sysctl.h>
+
+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)
[Message part 3 (text/plain, inline)]
Leo

This bug report was last modified 13 years and 37 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.