home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / misc / getloadavg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-23  |  4.2 KB  |  131 lines

  1. From daemon Fri Oct 23 02:19 PDT 1992
  2. Received: from sun2.nsfnet-relay.ac.uk by dns1.eecs.wsu.edu (16.6/5.910402)
  3.     id AA22066; Fri, 23 Oct 92 02:19:18 -0700
  4. Via: uk.ac.cambridge.mrc-applied-psychology; Fri, 23 Oct 1992 10:18:32 +0100
  5. Received: from menkar.mrc-apu.cam.ac.uk by sirius.mrc-apu.cam.ac.uk 
  6.           with UK-Sendmail (4.1/UK-2.1-APU); Fri, 23 Oct 92 10:18:05 BST
  7. Message-Id: <4517.9210230918@menkar.mrc-apu.cam.ac.uk>
  8. To: hlu@eecs.wsu.edu
  9. Subject: Re: mkstemp
  10. In-Reply-To: Your message of "Thu, 22 Oct 92 13:44:50 PDT." <9210222044.AA25828@yardbird>
  11. Date: Fri, 23 Oct 92 10:18:04 +0100
  12. From: Mitchum DSouza <mitchum.dsouza@mrc-apu.cam.ac.uk>
  13. Status: OR
  14.  
  15. Hi,
  16.  
  17. Thank you, mkstemp() works fine. I tried it with sendmail and it works....
  18. well somewhat.
  19.  
  20. I've got a few questions about debugging and shared libraries.
  21. I don't know if you know much about sendmail but here goes.
  22. When I build sendmail with shared libraries (jump 4.1), and attempt to build a
  23. frozen configuration file and the send some mail, sendmail coredumps. However
  24. if I make it a static binary everything works fine. The question is is how do
  25. I debug the shared version ?? I can't debug a shared version as -g forces
  26. static ?? or am i wrong ? I know quite a bit about C but not much about how to
  27. debug a core dump ??
  28.  
  29. Also if you put sendmail in deamon mode, (sendmail -bd), and incoming mail is
  30. recieved from say another Sun, then the forked process becomes defunct (as
  31. shown by ps) and a coredump is left in /usr/spool/mqueue. This happens for
  32. either the shared or static binary. So this question is - how do I debug a
  33. process that forks ?? i.e. a deamon ?
  34.  
  35. Any ideas would be greatly appreciated.
  36.  
  37. Thanx in advance.
  38.  
  39. P.S. here is getloadavg() from sendmail (but doesn't work on Linux)
  40. I don't know much about the kernel to make this work. Any ideas ??
  41.  
  42.  
  43.  
  44. /*
  45.  * Copyright (c) 1989 The Regents of the University of California.
  46.  * All rights reserved.
  47.  *
  48.  * Redistribution and use in source and binary forms are permitted
  49.  * provided that the above copyright notice and this paragraph are
  50.  * duplicated in all such forms and that any documentation,
  51.  * advertising materials, and other materials related to such
  52.  * distribution and use acknowledge that the software was developed
  53.  * by the University of California, Berkeley.  The name of the
  54.  * University may not be used to endorse or promote products derived
  55.  * from this software without specific prior written permission.
  56.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  57.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  58.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  59.  */
  60.  
  61. #if defined(LIBC_SCCS) && !defined(lint)
  62. static char sccsid[] = "@(#)getloadavg.c    6.1 (Berkeley) 5/29/89";
  63. #endif LIBC_SCCS and not lint
  64.  
  65. #include <sys/param.h>
  66. #include <sys/types.h>
  67. #include <sys/file.h>
  68.  
  69. /*#include <nlist.h>*/
  70. #include <paths.h>
  71. #define _PATH_KMEM "/dev/kmem"
  72. #define _PATH_UNIX "/dos/image"
  73.  
  74. static char *kmem = _PATH_KMEM;
  75. static char *vmunix = _PATH_UNIX;
  76.  
  77. static struct nlist nl[] = {
  78.     { "_averunnable" },
  79. #define    X_AVERUNNABLE    0
  80.     { "_fscale" },
  81. #define    X_FSCALE    1
  82.     { "" },
  83. };
  84.  
  85. /*
  86.  *  getloadavg() -- Get system load averages.
  87.  *
  88.  *  Put `nelem' samples into `loadavg' array.
  89.  *  Return number of samples retrieved, or -1 on error.
  90.  */
  91. getloadavg(loadavg, nelem)
  92.     double loadavg[];
  93.     int nelem;
  94. {
  95.     off_t lseek();
  96.     static int need_nlist = 1;
  97.     u_long averunnable[3];
  98.     int fscale, kmemfd, i;
  99.  
  100.     /* nlist() is slow; cache result */
  101.     if (need_nlist) {
  102.         if (nlist(vmunix, nl) != 0)
  103.             return (-1);
  104.         if (nl[X_AVERUNNABLE].n_type == 0 || nl[X_FSCALE].n_type == 0)
  105.             return (-1);
  106.         need_nlist = 0;
  107.     }
  108.  
  109.     if ((kmemfd = open(kmem, O_RDONLY, 0)) < 0)
  110.         return (-1);
  111.     if (lseek(kmemfd, (off_t)nl[X_AVERUNNABLE].n_value, L_SET) == -1)
  112.         goto bad;
  113.     if (read(kmemfd, (char *)averunnable, sizeof(averunnable)) < 0)
  114.         goto bad;
  115.     if (lseek(kmemfd, (off_t)nl[X_FSCALE].n_value, L_SET) == -1)
  116.         goto bad;
  117.     if (read(kmemfd, (char *)&fscale, sizeof(fscale)) < 0)
  118.         goto bad;
  119.     (void) close(kmemfd);
  120.  
  121.     nelem = MIN(nelem, sizeof(averunnable) / sizeof(averunnable[0]));
  122.     for (i = 0; i < nelem; i++)
  123.         loadavg[i] = (double) averunnable[i] / fscale;
  124.     return (nelem);
  125.  
  126. bad:
  127.     (void) close(kmemfd);
  128.     return (-1);
  129. }
  130.  
  131.