[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

portable implementation of load-average

From: Joe Buehler
Subject: portable implementation of load-average
Date: Wed, 22 Sep 2004 08:34:47 -0400
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040803

My AIX 4.3 boxes did not support load average in the modeline
(emacs 21.2 if it matters) so I fixed it.

Looking at this, it appears to be because /dev/kmem needs to be read
for the information, and setting emacs setgid to group 0 would be a big
security hole.

Attached is a portable implementation in LISP that uses the
"uptime" program.  Please consider adding this to emacs.  You should
have a copyright assignment on file for me for emacs.

The "uptime" program provides compatible output
formats (and so the below works) on AIX 4.3, AIX 5.2, Solaris 8,
HPUX 11, HPUX 11i, RedHat 9 -- all the machines to which I have access.

I'm not a LISP programmer -- feel free to do whatever with
my implementation if you don't like it.
Joe Buehler

;; supply a portable definition of load-average if the emacs one does not work
(condition-case nil
   (defun load-average (&optional wantfloat)
         "get load average"
         (let ((uptime (shell-command-to-string "/usr/bin/uptime")))
           (if (string-match "load average: \\([0-9.]+\\), \\([0-9.]+\\), 
\\([0-9.]+\\)" uptime)
                   (if wantfloat
                                (string-to-number (match-string 1 uptime))
                                (string-to-number (match-string 2 uptime))
                                (string-to-number (match-string 3 uptime))
                          (truncate (* 100 (string-to-number (match-string 1 
                          (truncate (* 100 (string-to-number (match-string 2 
                          (truncate (* 100 (string-to-number (match-string 3 
                 (if wantfloat
                         (list 0.0 0.0 0.0)
                   (list 0 0 0)

;;;;;; the end

reply via email to

[Prev in Thread] Current Thread [Next in Thread]