xref: /dflybsd-src/libexec/atrun/gloadavg.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1*86d7f5d3SJohn Marino /*
2*86d7f5d3SJohn Marino  *  gloadavg.c - get load average for Linux
3*86d7f5d3SJohn Marino  *  Copyright (C) 1993  Thomas Koenig
4*86d7f5d3SJohn Marino  *
5*86d7f5d3SJohn Marino  * Redistribution and use in source and binary forms, with or without
6*86d7f5d3SJohn Marino  * modification, are permitted provided that the following conditions
7*86d7f5d3SJohn Marino  * are met:
8*86d7f5d3SJohn Marino  * 1. Redistributions of source code must retain the above copyright
9*86d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer.
10*86d7f5d3SJohn Marino  * 2. The name of the author(s) may not be used to endorse or promote
11*86d7f5d3SJohn Marino  *    products derived from this software without specific prior written
12*86d7f5d3SJohn Marino  *    permission.
13*86d7f5d3SJohn Marino  *
14*86d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15*86d7f5d3SJohn Marino  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16*86d7f5d3SJohn Marino  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17*86d7f5d3SJohn Marino  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18*86d7f5d3SJohn Marino  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19*86d7f5d3SJohn Marino  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20*86d7f5d3SJohn Marino  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21*86d7f5d3SJohn Marino  * THEORY OF LIABILITY, WETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22*86d7f5d3SJohn Marino  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23*86d7f5d3SJohn Marino  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*86d7f5d3SJohn Marino  *
25*86d7f5d3SJohn Marino  * $FreeBSD: src/libexec/atrun/gloadavg.c,v 1.6 2007/06/15 10:12:37 yar Exp $
26*86d7f5d3SJohn Marino  * $DragonFly: src/libexec/atrun/gloadavg.c,v 1.3 2004/02/03 23:24:50 rob Exp $
27*86d7f5d3SJohn Marino  */
28*86d7f5d3SJohn Marino 
29*86d7f5d3SJohn Marino /* System Headers */
30*86d7f5d3SJohn Marino 
31*86d7f5d3SJohn Marino #include <stdlib.h>
32*86d7f5d3SJohn Marino 
33*86d7f5d3SJohn Marino /* Local headers */
34*86d7f5d3SJohn Marino 
35*86d7f5d3SJohn Marino #include "gloadavg.h"
36*86d7f5d3SJohn Marino 
37*86d7f5d3SJohn Marino /* Global functions */
38*86d7f5d3SJohn Marino 
39*86d7f5d3SJohn Marino void perr(const char *fmt, ...);
40*86d7f5d3SJohn Marino 
41*86d7f5d3SJohn Marino double
gloadavg(void)42*86d7f5d3SJohn Marino gloadavg(void)
43*86d7f5d3SJohn Marino /* return the current load average as a floating point number, or <0 for
44*86d7f5d3SJohn Marino  * error
45*86d7f5d3SJohn Marino  */
46*86d7f5d3SJohn Marino {
47*86d7f5d3SJohn Marino     double result;
48*86d7f5d3SJohn Marino     if (getloadavg(&result, 1) != 1)
49*86d7f5d3SJohn Marino 	    perr("error in getloadavg");
50*86d7f5d3SJohn Marino     return result;
51*86d7f5d3SJohn Marino }
52