executing a stream

Barry Margolin barmar at think.com
Thu Jan 17 07:19:10 AEST 1991


In article <1991Jan15.204849 at IASTATE.EDU> spam at IASTATE.EDU (Begley Michael L) writes:
>   uncompress -c microemacs|execute   /* uncompress microemacs.Z     */
>                                      /* into a stream, and execute  */

>I've been told that it can't be done because of swapping...
>Can anyone help?

It's doable, but not trivial.  Basically, the execute command would have to
duplicate the functionality of the kernel's exec*() system calls.  It could
fork a process, and then use something like ptrace() to initialize the
process from the contents of stdin.  It would have to recognize all the
appropriate magic numbers, parse executable file headers, locate all the
sections of the input stream (text, bss, data), perhaps fill in the user
data structure with something more useful than "execute", fill in argv,
argc, hardware registers, and set the PC so that execution begins at the
appropriate place.  I don't think it can be written portably.

Swapping isn't a problem; the process will simply page out of the swap
area, rather than directly from the executable (since there isn't an
executable).

Sounds like an interesting project, and it would be a fine example to use
whenever the "how do I find the pathname of the current executable"
question comes up.
--
Barry Margolin, Thinking Machines Corp.

barmar at think.com
{uunet,harvard}!think!barmar



More information about the Comp.unix.internals mailing list