home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- 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
- From: peter@merlin.acadiau.ca (Peter Steele)
- Subject: Re: Simultaneous processes
- Message-ID: <root.714927439@merlin>
- Sender: news@dragon.acadiau.ca
- Nntp-Posting-Host: merlin
- Organization: Acadia University
- References: <root.714838821@merlin> <mcook.714854903@fendahl.dev.cdx.mot.com>
- Date: Thu, 27 Aug 1992 14:57:19 GMT
- Lines: 64
-
- >>How does one set up simultaneous processes in perl? For example,
- >>how would I translate the following into perl:
-
- >> ls -la > d1 &
- >> ls -la > d2 &
- >> ls -la > d3 &
- >> wait
- >> cat d1 d2 d3 > d4
-
- >It would probably be enough to wait for them in the order they were started.
- >For example, here's the logic from a script I use run parallel rsh's:
-
- >foreach $host (@host)
- >{
- > open($host, "rsh $host $command |") || die "popen";
- >}
- >foreach $host (@host)
- >{
- > while (<$host>)
- > {
- > &do_something_with($_);
- > }
- > close($host);
- >}
-
- I don't know perl well enough to know if this will do what I want.
- Full parallelism is needed as this script is intended to perform
- disk I/O benchmarking. I decided to (gasp) hack something together
- in C-shell. I've included it below; if someone wants to convert this
- to perl or Bourne shell, I'd be interested in seeing it.
-
- #!/bin/csh
- # Usage: iotest drive1list drive2list
- # The drive lists are comma-separated lists. This routine might be
- # called using "iotest usr,var cs1,cs2,users". Output is collected
- # in /tmp/final.results.
-
- set dlist1=`echo $1 | tr ',' ' '`
- set dlist2=`echo $2 | tr ',' ' '`
- set size=$3
-
- cp /dev/null /tmp/final.results
-
- @ i=1
- while ($i <= $#dlist1)
- @ j=0
- while ($j <= $#dlist2)
- @ b=1
- foreach d ($dlist1[1-$i] $dlist2[1-$j])
- benchmark $d >/tmp/results.$b &
- @ b++
- end
- wait
- cat /tmp/results.* >>/tmp/final.results
- echo '+++++++++++++++++++++++++++++++++++++' >>/tmp/final.results
- rm /tmp/results.*
- @ j++
- end
- @ i++
- end
-
- --
- Peter Steele Unix Services Manager peter.steele@acadiau.ca
- Acadia Univ., Wolfville, NS, Canada B0P 1X0 902-542-2201 Fax: 902-542-4364
-