all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* portable implementation of load-average
@ 2004-09-22 12:34 Joe Buehler
  2004-09-22 13:37 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Buehler @ 2004-09-22 12:34 UTC (permalink / raw)


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
	(load-average)
   (error
    (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
			   (list
				(string-to-number (match-string 1 uptime))
				(string-to-number (match-string 2 uptime))
				(string-to-number (match-string 3 uptime))
				)
			 (list
			  (truncate (* 100 (string-to-number (match-string 1 uptime))))
			  (truncate (* 100 (string-to-number (match-string 2 uptime))))
			  (truncate (* 100 (string-to-number (match-string 3 uptime))))
			  )
			 )
		 (if wantfloat
			 (list 0.0 0.0 0.0)
		   (list 0 0 0)
		   )
		 )
	   )
	 )
    ))

;;;;;; the end

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-09-22 13:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-22 12:34 portable implementation of load-average Joe Buehler
2004-09-22 13:37 ` Stefan Monnier
2004-09-22 13:59   ` Joe Buehler

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.