* Re: "fork" in OpenVMS C compiler
[not found] <4hk71r$76o@graph24.unipv.it>
@ 1996-03-08 5:00 ` David Bratton
[not found] ` <4hq7p6$nv0@blixen.aquilagroup.com>
1996-03-13 5:00 ` Carl J. Appellof
2 siblings, 0 replies; 4+ messages in thread
From: David Bratton @ 1996-03-08 5:00 UTC (permalink / raw)
To: Alessandro Bruciamonti
Alessandro Bruciamonti wrote:
>
> Hello all!
>
> I'm doing a porting of some software from Unix (Sun Solaris 2.3) to
> OpenVMS (DEC OpenVMS AXP - V6.1-1H2).
>
> This software uses (intensively) the "fork" C function to open a "child"
> (independent and reentrant) process that runs concurrently with the
> parent process.
>
> On DEC I saw a similar function named "vfork", but I can't replace
> "fork" with "vfork" as this is not reentrant (the child
> process is started, but it never returns control to the parent, nor
> allows the parent process to run cuncurrently)...
>
> Is there a replacement for "fork" for VMS C compilers ?
>
> Thank you in advance ...
>
> Greetings from Italy!
>
> --
> Alessandro "Alex" Bruciamonti
> --
> alex@gateway.unipv.it (INTERNET)
> IW2CNM@IK2HDG.ILOM.ITA.EU (AX-25)
I think the LIB$SPAWN rtl routine is what you want.
David Bratton
University of Houston System
DBratton@uh.edu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: "fork" in OpenVMS C compiler
[not found] ` <4hq7p6$nv0@blixen.aquilagroup.com>
@ 1996-03-09 5:00 ` David Bratton
1996-03-11 5:00 ` Christopher M. Conway
0 siblings, 1 reply; 4+ messages in thread
From: David Bratton @ 1996-03-09 5:00 UTC (permalink / raw)
In article <4hq7p6$nv0@blixen.aquilagroup.com>, wombat@barq.aquilagroup.com (Christopher M. Conway) writes:
>
>About 5 or so years back, I was doing a very similar thing-- porting a shell
>interpreter from a Sun running SunOS 4.1 to a VMS 5.3 system.
>
>I went through *hell* with getting child processes going, and never did
>get them in a way I was happy. VMS (at least at the time, 6.x may be
>different) really didn't like to spawn new processes.
>
>I ended up having to right my own fork function, using their degenerate
>one, as I recall. I believe the end result was that I had to run a
>system(2) call on "spawn/detach program.exe" to get a new program forked.
>I then had to open a pipe to it to pass execution information on. It was
>really ugly and slow as molasses-- took as much as 3-4 *seconds* to spawn a
>new process.
>
>If you just want a forked copy of the parent process, with the same
>environment, you're basically out of luck.
>
>Again, this is as of VMS 5.3. Things may have changed; hopefully some
>VMS wizard will tell me/you of some really simple and efficient way to
>do it, but I doubt it. VMS just doesn't like process spawning.
>
>I'd be happy to dig up my old code for you if you like. Like I said, it's
>not pretty, but it worked.
>
>--
>Christopher M. Conway wombat@aquilagroup.com
>
>Don't Tread on Me
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.
Most environment information is inherited by the new process. Logical names
created with the /JOB qualifier are shared between parent and child process
via a common logical name table.
You can also create processes via Decnet -
ie. nodename"userid password"::TASK=command-procedure.
You can also RUN SYS$SYSTEM:LOGINOUT.EXE/lots-of-qualifiers.
You can also use the system service $CREPRC.
SHEESH!!! Did you really have trouble with this?
David Bratton
University of Houston System
DBratton@uh.edu
------------------------------------------------------------------------------
David Bratton
University of Houston System
DBratton@uh.edu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: "fork" in OpenVMS C compiler
1996-03-09 5:00 ` David Bratton
@ 1996-03-11 5:00 ` Christopher M. Conway
0 siblings, 0 replies; 4+ messages in thread
From: Christopher M. Conway @ 1996-03-11 5:00 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: "fork" in OpenVMS C compiler
[not found] <4hk71r$76o@graph24.unipv.it>
1996-03-08 5:00 ` "fork" in OpenVMS C compiler David Bratton
[not found] ` <4hq7p6$nv0@blixen.aquilagroup.com>
@ 1996-03-13 5:00 ` Carl J. Appellof
2 siblings, 0 replies; 4+ messages in thread
From: Carl J. Appellof @ 1996-03-13 5:00 UTC (permalink / raw)
I don't know why this note has generated all those heated replies.
I've ported a major application from UNIX to VMS, and I can tell you
that LIB$SPAWN() is nowhere close to a replacement for fork()!
If you want a real fork(), use the VMS POSIX environment. It provides a
pretty comfortable way of porting UNIX code.
--
Carl Appellof
not speaking for
Digital Equipment Corporation
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1996-03-13 5:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <4hk71r$76o@graph24.unipv.it>
1996-03-08 5:00 ` "fork" in OpenVMS C compiler David Bratton
[not found] ` <4hq7p6$nv0@blixen.aquilagroup.com>
1996-03-09 5:00 ` David Bratton
1996-03-11 5:00 ` Christopher M. Conway
1996-03-13 5:00 ` Carl J. Appellof
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox