home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume10 / readstts.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-27  |  4.6 KB  |  158 lines

  1. From decwrl!shelby!rutgers!usc!samsung!uunet!allbery Tue Jan 30 09:20:20 PST 1990
  2. Article 1318 of comp.sources.misc:
  3. Path: decwrl!shelby!rutgers!usc!samsung!uunet!allbery
  4. From: gwollman@JHMAIL.HCF.JHU.EDU (GAWollman)
  5. Newsgroups: comp.sources.misc
  6. Subject: v10i048: readstats... simple process-statistics program
  7. Message-ID: <77901@uunet.UU.NET>
  8. Date: 28 Jan 90 18:33:43 GMT
  9. Sender: allbery@uunet.UU.NET
  10. Lines: 143
  11. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  12.  
  13. Posting-number: Volume 10, Issue 48
  14. Submitted-by: gwollman@JHMAIL.HCF.JHU.EDU (GAWollman)
  15. Archive-name: readstats.c
  16.  
  17. Mr. Moderator, I don't know why I decided to send this program, but I
  18. am.  It is a ridiculously simple program to read a set of statistics
  19. from the standard input, form an average, and print out the result.
  20. The Makefile is longer than the program.
  21. I let it speak for itself... there is also a readme file.
  22.      
  23. -GAWollman
  24. "All societies are based on rules to protect pregnant women and children.
  25.  . . . As racial survival is the only universal morality, no other bases
  26.  is possible."           - Lazarus Long [RAH, _TEFL_]
  27. ---------------Hopkins doesn't *want* my opinions------------------------
  28.      
  29. ----------cut here------------
  30. #! /bin/sh
  31. # This is a shell archive, meaning:
  32. # 1. Remove everything above the #! /bin/sh line.
  33. # 2. Save the resulting text in a file.
  34. # 3. Execute the file with /bin/sh (not csh) to create:
  35. #       readstats.c
  36. #       Makefile
  37. #       README
  38. # This archive created: Fri Jan 26 19:16:53 1990
  39. export PATH; PATH=/bin:/usr/bin:$PATH
  40. echo shar: "extracting 'readstats.c'" '(364 characters)'
  41. if test -f 'readstats.c'
  42. then
  43.         echo shar: "will not over-write existing file 'readstats.c'"
  44. else
  45. sed 's/^X//' << \SHAR_EOF > 'readstats.c'
  46. X#include <stdio.h>
  47. X
  48. Xint main(argc,argv)
  49. Xint argc;
  50. Xchar **argv;
  51. X{
  52. X       /* actually, we don't need the arguments yet */
  53. X       int count_proc=0,count_rn=0;
  54. X       int i;
  55. X
  56. X       while(!feof(stdin)) {
  57. X               scanf("%d",&i);
  58. X               count_proc += i - 1;
  59. X               scanf("%d",&i);
  60. X               count_rn += i;
  61. X       }
  62. X       printf("%4.2f%% of all processes are RN\n",(double)count_rn * 100.0 /
  63. X               (double)count_proc);
  64. X       return 0;
  65. X}
  66. X
  67. SHAR_EOF
  68. if test 364 -ne "`wc -c < 'readstats.c'`"
  69. then
  70.         echo shar: "error transmitting 'readstats.c'" '(should have been 364 cha
  71. fi
  72. fi
  73. echo shar: "extracting 'Makefile'" '(643 characters)'
  74. if test -f 'Makefile'
  75. then
  76.         echo shar: "will not over-write existing file 'Makefile'"
  77. else
  78. sed 's/^X//' << \SHAR_EOF > 'Makefile'
  79. X#
  80. X# god, this is so disgustingly simple, I don't know why I
  81. X# bother with a makefile...
  82. X#
  83. X
  84. X# define this to the correct flag to use shared C libraries
  85. XSHLIBS= -lc_s
  86. X
  87. X# define this to be where you want the program installed, if at all
  88. XDESTDIR=/i/ins4/.gwollman/bin
  89. X
  90. Xall: readstats
  91. X
  92. Xclean:
  93. X       rm -f core
  94. X       rm -f a.out
  95. X#not that we generate any of these....
  96. X
  97. Xreadstats: readstats.c
  98. X       cc -o readstats readstats.c $(SHLIBS)
  99. X
  100. X# what could be simpler than that...
  101. X
  102. Xinstall:
  103. X       cp readstats $(DESTDIR)/readstats
  104. X       chmod 555 $DESTDIR/readstats
  105. X#      chown bin $DESTDIR/readstats
  106. X#      chgrp bin $DESTDIR/readstats
  107. X
  108. X# ... the makefile is longer than the program... !
  109. SHAR_EOF
  110. if test 643 -ne "`wc -c < 'Makefile'`"
  111. then
  112.         echo shar: "error transmitting 'Makefile'" '(should have been 643 charac
  113. fi
  114. fi
  115. echo shar: "extracting 'README'" '(849 characters)'
  116. if test -f 'README'
  117. then
  118.         echo shar: "will not over-write existing file 'README'"
  119. else
  120. sed 's/^X//' << \SHAR_EOF > 'README'
  121. X...
  122. XReadstats is a program I created for a personal survey I am doing
  123. Xto find out how many people are using the RN newsreader at any one
  124. Xtime.  It is a very simple program, which reads pairs of numbers from
  125. Xthe standard input and writes a percentage, total (second number) /
  126. Xtotal (first number), to the standard output:
  127. X
  128. X  9.42% of all processes are RN
  129. X
  130. Xwhich you would probably want to change, unless you *were* counting RNs
  131. Xon your system.
  132. X
  133. XTo make the count work, I have a line like this in all my .profiles:
  134. X
  135. X(ps -a | tee /tmp/rn.stats | wc -l ; grep "rn" /tmp/rn.stats | \
  136. X wc -l) >>rn.stats
  137. X
  138. XAs you can see, my count does not include system processes.  This is
  139. Xbecause we have about fifteen getty's running at one time, not to mention
  140. Xother denizens of a 3B4000.
  141. X
  142. XEnjoy!
  143. X
  144. X-GAWollman
  145. X
  146. XCopyright 1990, Garrett A. Wollman.  No rights reserved.
  147. X
  148. SHAR_EOF
  149. if test 849 -ne "`wc -c < 'README'`"
  150. then
  151.         echo shar: "error transmitting 'README'" '(should have been 849 characte
  152. fi
  153. fi
  154. exit 0
  155. #       End of shell archive
  156.  
  157.  
  158.