Path: utzoo!mnetor!uunet!husc6!mailrus!ames!ucsd!sdcsvax!ucsdhub!jack!elgar!ford
From: ford@elgar.UUCP (Ford Prefect )
Newsgroups: comp.sys.amiga
Subject: Re: Unix on the Amiga
Message-ID: <146@elgar.UUCP>
Date: 8 May 88 17:15:34 GMT
References: <8805042034.AA15057@cory.Berkeley.EDU> <1932@sugar.UUCP>
Reply-To: ford@kenobi.UUCP (Mike "Ford" Ditto)
Organization: Omnicron Data Systems, Bonita, CA
Lines: 63
Summary: vfork is better than fork, and it can be done on the Amiga

In article <1932@sugar.UUCP> peter@sugar.UUCP (Peter da Silva) writes:
>:Consider this a challenge, if you like... I don't think it's possible to
>:implement fork on the Amiga in the general case.
>
>In article ... dillon@CORY.BERKELEY.EDU (Matt Dillon) replied:
>> 	I never liked fork() anyway.  It is cute conceptually but not very
>> powerful.... more like wastefull.
>
>I know it's less filling. I just said that, Matt. Argh.
>
>The problem is that if you're going to emulate UNIX on the Amiga (see that
>there Subject: line?) you need to emulate fork(). There's no question about
>it. It's one of the core system calls.

99 percent of all forks could be vforks instead.  Vfork is better
because it doesn't actually create a whole new process, just another
thread in the old memory space.  The parent thread is put in suspended
animation until the child thread does an exit() or an exec().  This
results in a very efficient creation of a subprocess executing another
file, without making a copy (virtually or otherwise) of the parent
process's memory space.  It's functionally similar to Aztec's fexec(),
but with the semantics of fork (at least in terms of what the
program's source code looks like).

This works fine on the Amiga:

	pid = vfork();
	switch(pid) {
		case -1: perror("vfork"); exit(1);
		case 0:	 puts("parent: the child is off and running"); break;
		default: execvp(prog, args);
			 perror("execvp"); exit(1);
	}

vfork() is in my Unix compatibility library for the Amiga.  I did not
call it fork() just to force a manual inspection of calls to fork() to
see if they are replacable by vfork().  Almost all are, but I still
don't want to claim that my library does something that it can't.

Many versions of Unix have vfork already... I think it's standard on
BSD, and I've used it on a few SysV systems.

It turns out that wait() is more difficult to implement on the Amiga
than vfork() was (I'm still working on wait()).

Incedentally, the System V Interface Definition encourages the use of
system() rather than fork().  This is an especially good idea on
AmigaDos, since the command-string that is passed to system() can be
directly passed to Execute(), while the argv that is passed to exec
(after forking) must be re-assembled into a CLI command string.  This
is not always consistent with Unix; for example, some programs do an
exec() expecting each element of argv to be passed to the executed
program exactly as is, but on the Amiga argv gets recombinified into a
command-string and then transmogrified back into an argv.  system() is
a bit more predictable since it's argument is *supposed* to be parsed
and split into argv[].

					-=] Ford [=-

"Once there were parking lots,		(In Real Life:  Mike Ditto)
now it's a peaceful oasis.		ford%kenobi@crash.CTS.COM
This was a Pizza Hut,			...!sdcsvax!crash!kenobi!ford
now it's all covered with daisies." -- Talking Heads