Path: utzoo!censor!geac!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!samsung!think.com!barmar From: barmar@think.com (Barry Margolin) Newsgroups: comp.unix.internals Subject: executing a stream Message-ID: <1991Jan16.201910.8646@Think.COM> Date: 16 Jan 91 20:19:10 GMT References: <1991Jan15.204849@IASTATE.EDU> Sender: news@Think.COM Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 29 In article <1991Jan15.204849@IASTATE.EDU> spam@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@think.com {uunet,harvard}!think!barmar