home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume6 / pipes < prev    next >
Text File  |  1989-03-20  |  3KB  |  102 lines

  1. Newsgroups: comp.sources.misc
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Subject: v06i069: bug fix in pipes.c of byte benchmark
  4. Message-Id: <328@ssp2.idca.tds.philips.nl>
  5. Organization: Philips Telecommunication and Data Systems, The Netherlands
  6. Reply-To: pb@idca.tds.PHILIPS.nl (Peter Brouwer)
  7.  
  8. Posting-number: Volume 6, Issue 69
  9. Submitted-by: pb@idca.tds.PHILIPS.nl (Peter Brouwer)
  10. Archive-name: pipes
  11.  
  12. A few month a received a set of sources of the second byte benchmark.
  13. One of the tests is a pipe throughput test.
  14. This source file contains a bug. 
  15. The test was done as follows:
  16.  
  17.         open pipe;
  18.         fork;
  19.         if child ( read n times x bytes )
  20.         if parent ( write n times x byte )
  21.  
  22. This may not always work. When reading from a pipe not the same number of bytes
  23. may be received as is written on the other side in one write read pair.
  24. So we changed the receive loop so that the total number of bytes to be received
  25. is used in the receive loop.
  26. Below is the modified source.
  27.  
  28. #  Peter Brouwer,                     ##
  29. #  Philips TDS, Dept SSP-V2           ## voice +31 55 432523
  30. #  P.O. Box 245                       ## UUCP address ..!mcvax!philapd!pb
  31. #  7300 AE Apeldoorn, The Netherlands ## Internet pb@idca.tds.philips.nl
  32. -----Cut Here-----Cut Here-----Cut Here-----Cut Here-----
  33. : #!/bin/sh
  34. : # shar:    Shell Archiver
  35. : #    Run the following text with /bin/sh to create:
  36. : #    pipes.c
  37. echo shar extracting: pipes.c
  38. sed 's/^X//' << '!FUNKY!FUNKY!STUFF!' > pipes.c
  39. X/* File: pipes.c - created by Marty Leisner */
  40. X/* leisner.Henr         1-Dec-87  8:55:04 */
  41. X
  42. X/* Copyright (C) 1987 by Martin Leisner. All rights reserved. */
  43. X
  44. X#ifndef    BLOCK_SIZE
  45. X#define BLOCK_SIZE     1000
  46. X#endif    /* BLOCK_SIZE */
  47. X
  48. X#define NUM_BLOCKS    1000
  49. Xchar buffer[BLOCK_SIZE];
  50. X
  51. Xmain()
  52. X{
  53. X    int pipefd[2];
  54. X    register int i;
  55. X    register int j;
  56. X    register int k;
  57. X    pipe(&pipefd);
  58. X    
  59. X    
  60. X    
  61. X    switch(fork()) {
  62. X        case 0:
  63. X            /* child code */
  64. X            for(i = 0, j=BLOCK_SIZE*NUM_BLOCKS; j>0 ; i++) {
  65. X                if((k = read(pipefd[0], &buffer, BLOCK_SIZE)) < 0)
  66. X                    break;
  67. X                j -= k;
  68. X            }
  69. X            printf("child done, i = %d\n", i);
  70. X            exit();
  71. X            break;
  72. X        case -1:
  73. X            perror("fork broke");
  74. X            exit();
  75. X        default:
  76. X            /* parent code */
  77. X            for(i = 0; i < NUM_BLOCKS; i++)
  78. X                if    (write(pipefd[1], &buffer, BLOCK_SIZE) != BLOCK_SIZE)
  79. X                    break;
  80. X                
  81. X            puts("parent done");
  82. X            wait((char *) 0);
  83. X            break;
  84. X    }
  85. X    return 0;
  86. X}
  87. X
  88. !FUNKY!FUNKY!STUFF!
  89. echo 'Orignal Sum -> 60843 2 pipes.c'
  90. echo -n 'Current Sum -> '
  91. sum pipes.c
  92. exit 0
  93. -- 
  94. #  Peter Brouwer,                     ##
  95. #  Philips TDS, Dept SSP-V2           ## voice +31 55 432523
  96. #  P.O. Box 245                       ## UUCP address ..!mcvax!philapd!pb
  97. #  7300 AE Apeldoorn, The Netherlands ## Internet pb@idca.tds.philips.nl
  98.  
  99.  
  100. ----- End Forwarded Message -----
  101.  
  102.