From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,2a278b4da5a63dde X-Google-Attributes: gid1164f8,public From: wombat@barq.aquilagroup.com (Christopher M. Conway) Subject: Re: "fork" in OpenVMS C compiler Date: 1996/03/11 Message-ID: <4i1p71$gut@blixen.aquilagroup.com> X-Deja-AN: 142282505 distribution: world sender: wombat@aquilagroup.com (Christopher M. Conway) references: <4hk71r$76o@graph24.unipv.it> <4hq7p6$nv0@blixen.aquilagroup.com> <4hr635$iig@masala.cc.uh.edu> organization: Prickly Wombat Enterprises reply-to: wombat@aquilagroup.com newsgroups: comp.sys.dec In article <4hr635$iig@masala.cc.uh.edu>, sapsadeb@UHSFIN.UHSA.UH.EDU (David Bratton) writes: - - If you had bothered to pick up and read an RTL manual you would have saved - yourself a lot of frustration. The library routine to create a sub-process - is LIB$SPAWN. To do it from DCL the command is SPAWN. The /NOWAIT or - /DETACH qualifiers are used to get the two processes to run asynchrously. - As I said, this was several years ago. I do remember the lib$spawn function, and remember that it didn't do what I needed. Things may have changed with VMS 6.0 and later. Looking at the doc for lib$spawn now, and looking at my code, I can see what it lacked. First, it will not execute an arbitrary file; quoting from the manual, "The CLI specified must reside in sys$system with a file type of EXE, and it must be installed. No directory or file type may be specified." I didn't want to have to deal with that level of stuff; I just wanted to run a new copy of my program. Sometimes, I didn't want to do that-- I wanted to run an entirely different program; say, for instance, show/process, and be able to snarf the data and send it elsewhere, or who knows what else; it's impossible to say, as this was a *shell*, not some stupid little analysis program or what-not. Open files are not inherited; I could not provide I/O redirection, which was a necessity. The C environment is not inherited; and that's what I was using, not the stupid logical names or what-have-you. Routine and image context is not inherited; so if I wanted to do something in parallel in the same code, I couldn't do it. The functions fork/exec provided in the C library wouldn't do this either; they blocked execution of the parent process until the child completed, and required the exec to immediately follow the fork (basically). Nor could I pass it argc/argv arguments. I probably could have passed most of this information via a command file and executed it using the CLI, but it seemed a little ugly to have to create/write/close/open/read/close a file in order to create a process. The actual steps I took did use the $creprc system call. First, I created a pipe; I had to then get the pipe's mailbox name. Then, I spawned a DCL interpreter, giving its input as the mailbox name for the pipe. I had to then spawn *another* pipe in order to talk to a running command, getting its filesystem locations. I then ordered the command interpreter to define a foreign command (my wrapper), and run it with the given input and output files (my pipe). Having finally gotten a copy of the wrapper to start, I could send to it copies of the image file to run, the arguments to give it, the C environment to provide, and all of the open files. Having done all this, the wrapper could now, finally, use the vfork/execve functions from the C library, send the child process's PID back to the calling function, and then finally exit. I'm trying to recall why all this was necessary-- it's been 6 years since I did this. The obvious initial solution is to use vfork/execve; but I seem to recall that the problem was that any changes in the parent process's file descriptors were reflected in the child process. I couldn't do I/O redirection as I needed to using those calls, and the VMS library calls aren't geared toward UNIX-style programming. Sure, the best solution in some ways would have been to restructure how the code did what it did-- I might have been able to do something amusing with process logicals or some such-- but I was trying to do a rehost, not a redesign. The code needed to support *both* a UNIX and a VMS environment, with as little extraneous code as possible-- particularly in things that were to be common functions, such as I/O redirection. Having to maintain two different *designs* to handle I/O redirection was much uglier than having to code around the OS differences. Sure, doing a from-the-bottom VMS implementation would have been more efficient-- but that's not what I was doing, nor did I have time to do it. I had to rehost about 25,000 lines of code in 3 months; including fun things like X windows stuff on top of all this. Anyway, to the original poster: I do have all that source. It includes all sorts of fun things that I vaguely remember having to work around; things that VMS didn't do or just didn't do quite right: uid/gid/passwd stuff; opening real pipes; alarms and timers; directory functions; rusage (which I seem to recall never worked very well); sleep/usleep; tsearch (I think I adapted this from the algorithms/code in _Algorithms + Data Structures = Programs_ by Niklaus Wirth); unlink; signal; qsort; putenv; I/O functions to allow non-blocking I/O and open file descriptors across execs; getopt (I think this is an old GNU version); file globbing; that sort of stuff. If you want it, you're welcome to it. I'll have to try to figure out again how some of it worked.... 8^{)> Hmm. On a quick look, the qsort I snarfed from the TI code for the DSP I was working on in relation to the project, so I can't give you that. You can probably get that, and some of the more standard stuff like tsearch, from the GNU libraries and be better off. For that matter, it might be worth looking at the GNU libraries to see if they solved all this stuff themselves.... a *REAL* C library would have done wonders for me at the time. -- Christopher M. Conway wombat@aquilagroup.com Don't Tread on Me