From owner-freebsd-questions Wed Sep 29 9:14: 2 1999 Delivered-To: freebsd-questions@freebsd.org Received: from silver.teardrop.org (silver.teardrop.net [216.155.28.66]) by hub.freebsd.org (Postfix) with ESMTP id 6EE12155DB for ; Wed, 29 Sep 1999 09:13:10 -0700 (PDT) (envelope-from sno@teardrop.org) Received: from localhost (sno@localhost) by silver.teardrop.org (8.9.3/8.9.2) with SMTP id MAA54150; Wed, 29 Sep 1999 12:11:44 -0400 (EDT) (envelope-from sno@teardrop.org) Date: Wed, 29 Sep 1999 12:11:44 -0400 (EDT) From: James Snow To: Steve Price Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Weird segfault In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 #include #include #include #include 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