No fork() in MSC5.0, help...

Dan Platt platt at emory.uucp
Thu Jul 21 12:15:15 AEST 1988


In article <9900005 at bradley> brian at bradley.UUCP writes:
>
>  I'm considering writing a shell for the IBM PC... I'm using Microsoft
>C 5.0. This version does not provide a fork() function. Instead, they
>provide a set of functions called spawn, which are similar to exec.
>That is, there is a spawnve(), spawnl(), etc. ...

There is no fork because  DOS doesn't support multitasking.  What
DOS will support is an interupt driven suspension of one routine and
activation of another routine (this is demonstrated in the DOS print
command), or for a software suspension of one routine for a temporary
execution of another one (until memory runs out) which is what spawnve()
etc. do.

>  Unfortunatley, to do I/O redirection, I need to put some code between
>the fork() and the exec() in the child process. Since there is not
>really a fork(), this isn't possible.

You want PIPEs.  Well, there aren't any real pipes in DOS (unlike UNIX)
since there is no multitasking.  However, there is re-direction and
DOS does support a pseudo-PIPE.  The way DOS does it is to have one
process direct stdout to a temporary file PIPE*.* which is then directed
to stdin of the next process.  Multiple pipes are possible, but each
process has to be able to run sequentially; they can't be written to
run concurrently with the process.  If you really want to sweat, you could
make a hybrid where an agreed upon temporary file was used as the input,
and have the secondary process execute a little on each clock interupt...

>
>  Of course, I could do a system() with my whole command line, but this
>is not a solution because 1) there is no way to pass the environment
>in this case, 2) I would have to somehow translate my shell's syntax
>back to MS-DOS COMMAND.COM syntax, which may not be possible, and
>3) the system() function probaly will load in another copy of COMMAND.COM,
>and my shell will be cutting into avaible memory at it is.
>
>  So what I need is a way to run a child process, with (possibly)
>redirected input and/or output, passing the environment, and having the
>parent process resume execution after the child process completes.
>Does anyone have any clues as to how this can be done?
>

The only way I can see you doing it is using spawnv*() with a
temporary file used to pass the information.  You may need to 
tolerate loaded versions of COMMAND.COM.  If you are only loading
one process at a time on top of your shell, this shouldn't be too
much of a problem unless your shell is large.  You may also want
to consider using exemod on your shell program to reduce the execution
space size (your shell will take up a lot more space than command.com
unless you do this).  Most of the spawn*() and system() function calls
use DOS BIOS function calls anyway.

This is one reason to 1) Go to UNIX systems, or 2) Go to OS/2 (if it
ever flies)...


Dan Platt



More information about the Comp.lang.c mailing list