*BSD News Article 56122


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.mel.connect.com.au!yarrina.connect.com.au!munnari.OZ.AU!spool.mu.edu!howland.reston.ans.net!news.sprintlink.net!tank.news.pipex.net!pipex!news.mathworks.com!newsfeed.internetmci.com!in1.uu.net!boulder!csnews!alumni!atk
From: atk@alumni.cs.Colorado.EDU (Alan T Krantz)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: Odd way of passing parameters
Date: 29 Nov 1995 16:49:38 GMT
Organization: University of Colorado, Boulder CS Dept
Lines: 25
Message-ID: <49i2v2$fa2@csnews.cs.colorado.edu>
References: <817632346snz@beckley.demon.co.uk>
NNTP-Posting-Host: alumni.cs.colorado.edu
X-Newsreader: TIN [version 1.2 PL2]

Ian W Taylor (iwta@beckley.demon.co.uk) wrote:
: Whilst working on some C code that was written in the late 70's
: (maybe early 80's) I came across the following code which seems
: to work under FreeBSD, but I can't quite decide whether it's a
: 'legal' ( for want of a better word ;-) ) way of using pipes.

: Code creates a pipe, the parent writes block to the pipe
: (approx 132 bytes), it then overwrites itself with execv()
: and then the new process reads its 'parameters' from the pipe.

: Any Thoughts ??

Well, looking at the man page for execv we see:

  File descriptors open in the calling process remain open  in
  the  new  process, except for those whose close-on-exec flag
  is set; (see fcntl(2)).  For  those  file  descriptors that
  remain open, the file pointer is unchanged.

Therefore this would seem to be perfectly legal - though I would think
that using execl (and passing the arguments on the command line) would
be both easier to understand and more efficient (well execv could also
be used).

atk