From owner-freebsd-hackers Thu Jul 15 10: 1:58 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from acl.lanl.gov (acl.lanl.gov [128.165.147.1]) by hub.freebsd.org (Postfix) with ESMTP id A486F155F5 for ; Thu, 15 Jul 1999 10:01:42 -0700 (PDT) (envelope-from rminnich@acl.lanl.gov) Received: from tbp.acl.lanl.gov (root@tbp.acl.lanl.gov [128.165.147.10]) by acl.lanl.gov (8.8.8/8.8.5) with ESMTP id LAA497410 for ; Thu, 15 Jul 1999 11:00:26 -0600 (MDT) Received: from localhost (rminnich@localhost) by tbp.acl.lanl.gov (8.8.7/8.8.8) with ESMTP id LAA12212 for ; Thu, 15 Jul 1999 11:00:11 -0600 X-Authentication-Warning: tbp.acl.lanl.gov: rminnich owned process doing -bs Date: Thu, 15 Jul 1999 11:00:11 -0600 (MDT) From: "Ronald G. Minnich" To: hackers@freebsd.org Subject: Another take on /proc statistics (joke of the day) Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I thought this amusing. Take the following program, designed to suck stats out of /proc for the network devices: #include #include #include main() { char stuff[4096]; int fd = open("/proc/net/dev", 0); while(1) { int amount = read(fd, stuff, sizeof(stuff)); if (amount > 0) write(1, stuff, amount); sleep(1); lseek(fd, (off_t) 0, SEEK_SET); } } Run this on linux, and you'll get the same values for all the stats. how to make it work right? #include #include #include main() { char stuff[4096]; while(1) { int fd = open("/proc/net/dev", 0); int amount; amount = read(fd, stuff, sizeof(stuff)); if (amount > 0) write(1, stuff, amount); close(fd); sleep(1); } } What are the implications of this? Well, if you have an rstatd that uses /proc for statistics, it will have to (for every request) open the status files, read them, and close them. Net result: very very poor performance for an rstatd (not even counting the fact that the rstatd has to parse formatted output back to a binary format ...) ron p.s. the rstatd I have for redhat does indeed read stats out of /proc ... To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message