Date: Wed, 29 Sep 1999 12:11:44 -0400 (EDT) From: James Snow <sno@teardrop.org> To: Steve Price <sprice@hiwaay.net> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Weird segfault Message-ID: <Pine.BSF.3.96.990929102030.53798A-100000@silver.teardrop.org> In-Reply-To: <Pine.OSF.4.10.9909282027170.23202-100000@fly.HiWAAY.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 28 Sep 1999, Steve Price wrote:
> On Tue, 28 Sep 1999, James Snow wrote:
>
> [snip]
> # int loadavg() {
> # double avg[2];
> ^
> Shouldn't this be 3?
Yes, I apologize. This was something that I changed when the problem was
first presented to me, but I had deleted my version of the code, and
copied the old one into my email.
The current code and behaviour follows:
silver:~> cat ut.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#include <sys/sysctl.h>
int uptime()
{
int mib[1];
int utsec, utday, uthour, utmin;
size_t len;
mib[0] = CTL_KERN;
mib[1] = KERN_BOOTTIME;
len = sizeof(utsec);
sysctl(mib, 2, &utsec, &len, NULL, 0);
utsec = time(NULL) - utsec;
utday = utsec / 86400;
utsec %= 86400;
uthour = utsec / 3600;
utsec %= 3600;
utmin = utsec / 60;
utsec %= 60;
return printf("%dd %dh:%dm:%ds\n", utday, uthour, utmin, utsec);
}
int loadavg() {
double avg[3];
if ((getloadavg(avg, 3)) == -1)
return printf("Not available\n");
return printf("%.2f %.2f %.2f\n", avg[0], avg[1], avg[2]);
}
int main() {
printf("a:");
uptime();
printf("b:");
loadavg();
printf("c:\n");
return 0;
}
silver:~> gcc ut.c
silver:~> ./a.out
a:6d 19h:29m:11s
b:0.11 0.06 0.01
c:
Segmentation fault(core dumped)
silver:~>
Thanks again.
-sno
o-( sno at teardrop dot org - I am Geek. Hear me ^G )-o
| CBFC 702E 0F86 29C6 4386 16DD 6B0B 0D56 D77A 5CD5 |
| 8B24 4914 605E BB0E 3E10 4A6C 261F 0BA0 386D 032A |
o-( We live in the short term and hope for the best )-o
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.96.990929102030.53798A-100000>
