Basic HTML version of Foils prepared March 30 97

Foil 79 Execution of UNIX Commands -- fork and exec (Chapter 15 of Llama Book)

From PERL4 Tutorial for CPS616 Computational Science for Information Age Course CPS616 -- February 1995. by Geoffrey C. Fox


1 This is most powerful method with fork creating two identical copies of program -- parent and child
2 unless (fork) { ;} # child indicated by fork=0
3 ; # otherwise fork=child process number for parent
4 The child program typically invokes exec which replaces child original by the argument of exec. Meanwhile parent should wait until this exec is complete and child has gone away.
5 unless (fork) {
  • exec("date"); # child process becomes date command sharing environment with parent
6 }
7 wait; # parent process waits until date is complete
8 The child process need not terminate naturally as with exec() and if child code was for instance
9 print FILEHANDLE @hugefile; # in parallel with parent
10 exit; # is required else child will continue with parents code whereas we wanted parent and child to work in parallel on separate jobs

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Sep 6 1997