home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5552 < prev    next >
Encoding:
Text File  |  1992-08-27  |  2.2 KB  |  77 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!caen!destroyer!ubc-cs!utcsri!torn!csd.unb.ca!morgan.ucs.mun.ca!nstn.ns.ca!dragon.acadiau.ca!merlin!peter
  3. From: peter@merlin.acadiau.ca (Peter Steele)
  4. Subject: Re: Simultaneous processes
  5. Message-ID: <root.714927439@merlin>
  6. Sender: news@dragon.acadiau.ca
  7. Nntp-Posting-Host: merlin
  8. Organization: Acadia University
  9. References: <root.714838821@merlin> <mcook.714854903@fendahl.dev.cdx.mot.com>
  10. Date: Thu, 27 Aug 1992 14:57:19 GMT
  11. Lines: 64
  12.  
  13. >>How does one set up simultaneous processes in perl? For example,
  14. >>how would I translate the following into perl:
  15.  
  16. >>    ls -la > d1 &
  17. >>    ls -la > d2 &
  18. >>    ls -la > d3 &
  19. >>    wait
  20. >>    cat d1 d2 d3 > d4
  21.  
  22. >It would probably be enough to wait for them in the order they were started.
  23. >For example, here's the logic from a script I use run parallel rsh's:
  24.  
  25. >foreach $host (@host)
  26. >{
  27. >    open($host, "rsh $host $command |") || die "popen";
  28. >}
  29. >foreach $host (@host)
  30. >{
  31. >    while (<$host>)
  32. >    {
  33. >        &do_something_with($_);
  34. >    }
  35. >    close($host);
  36. >}
  37.  
  38. I don't know perl well enough to know if this will do what I want.
  39. Full parallelism is needed as this script is intended to perform
  40. disk I/O benchmarking. I decided to (gasp) hack something together
  41. in C-shell. I've included it below; if someone wants to convert this
  42. to perl or Bourne shell, I'd be interested in seeing it.
  43.  
  44. #!/bin/csh
  45. # Usage: iotest drive1list drive2list
  46. # The drive lists are comma-separated lists. This routine might be
  47. # called using "iotest usr,var cs1,cs2,users". Output is collected
  48. # in /tmp/final.results.
  49.  
  50. set dlist1=`echo $1 | tr ',' ' '`
  51. set dlist2=`echo $2 | tr ',' ' '`
  52. set size=$3
  53.  
  54. cp /dev/null /tmp/final.results
  55.  
  56. @ i=1
  57. while ($i <= $#dlist1)
  58.     @ j=0
  59.     while ($j <= $#dlist2)
  60.         @ b=1
  61.         foreach d ($dlist1[1-$i] $dlist2[1-$j])
  62.             benchmark $d >/tmp/results.$b &
  63.             @ b++
  64.         end
  65.         wait
  66.         cat /tmp/results.* >>/tmp/final.results
  67.         echo '+++++++++++++++++++++++++++++++++++++' >>/tmp/final.results
  68.         rm /tmp/results.*
  69.         @ j++
  70.     end
  71.     @ i++
  72. end
  73.  
  74. --
  75. Peter Steele        Unix Services Manager            peter.steele@acadiau.ca 
  76. Acadia Univ., Wolfville, NS, Canada B0P 1X0  902-542-2201  Fax: 902-542-4364
  77.