From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Sat, 3 Jul 1999 16:22:21 +0100 From: Digby Tarvin digbyt@acm.org Subject: [9fans] spawn() vs fork() Topicbox-Message-UUID: 998b3354-eac8-11e9-9e20-41e7f4b1d025 Message-ID: <19990703152221.qcf4sgrSd3VPYTezP39jPzCwOMbviZEUE8wWyA-Toug@z> > >Imagine how you would do IO redirection with spawn(). > I don't have to imagine - I have done a lot of work with the OS-9 operating sytem which does just that. OS-9 dates back to the time when memory management with dynamic address translation was pretty rare and exotic (originally ran on M6809) so for maximum hardware portability the system assumes that everything works on physical addresses. MMU, if available, is only used to restrict read/write access. That compromise meant that a fork() style of process creation was not possible (all pointers in the child's data segment would be pointing into the parents memory), so it uses a spawn() style of process creation. I/O redirection is implemented using a flurry of dup(), close() open() calls before and after the child is created (combined with the ability to control how many open file descriptors are passed on to the child). Fork() is a much more elegant way of giving code in the parent process a chance to initialise the environment for the child before transferring control - not only I/O, but also current directory, UID, priority etc, all without having to define a set of additional system calls or adding a long list of arguments to the spawn request... On the down side, appart from relying on address translation, fork() is usually more complex to implement in the kernel, and a fork()/exec() sequence usually involves more run time overhead than a single combined semantic. Regards, DigbyT -- Digby R. S. Tarvin digbyt@acm.org http://www.cthulhu.dircon.co.uk