home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume10 / readstats.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-28  |  4.3 KB  |  150 lines

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