Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[BLU] the philosophy of fork/exec



On Fri, 19 Jan 2001, Seth Gordon wrote:

> > ...The recent
> > description of unix's file-linking scheme as "strange" is an
> > example
> > of  how  even  experienced  unix  users  and programmers don't
> > always
> > understand the reasons behind the design.  The unix fork+exec
> > scheme
> > is another.
>
> Can you expand on this?  What do other OSs do for spawning a process
> that don't fit the fork+exec model, what are the consequences of those
> alternative techniques, and what problems does fork+exec solve?

Nobody bit on this one, so I will attempt to answer the question, though
it is outside any areas of expertise I pretend to have.


In the UNIX world, if you want to have another process do some work for
you, you call fork(), which will make an exact copy of the current
process, including variables, etc.  If fork() returns a PID, then you are
the parent copy. You cna either wait for the chid to finish, or go off and
do something else, whatever.  If fork() returns zero, then you are the
child.  The code branches off in a different direction, possibly calling
exec() to exit the current program and execute another one.  But the
important thing is that fork() creates two processes running the same
code, and both copies will typcally check the return value of fork() to
see what to do next,

In the Windows world, you don't have fork(), you have spawn().  Spawn()
will start up another process, and that other process may be identical to
the one currently running, or may be a completely different command or
parameters.  So program A spawns program B.  You also have exec(), but it
normally would not be used in conjunction with spawn().

You can see how these are very different solutions with different
advantages and disadvantages.

-------------------------------------------------------------------
DDDD   David Kramer                   http://thekramers.net
DK KD
DKK D  Football is not a contact sport; it is a collision sport.
DK KD  Dancing is a contact sport.              --Vince Lombardi
DDDD



-
Subcription/unsubscription/info requests: send e-mail with
"subscribe", "unsubscribe", or "info" on the first line of the
message body to discuss-request at blu.org (Subject line is ignored).




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org