Operating System - OpenVMS
Showing results for 
Search instead for 
Did you mean: 

equivalent of fork() in OpenVMS

Occasional Visitor

equivalent of fork() in OpenVMS

I am writing a C code in OpenVMS.
I would like to know what how to create a child process in OpenVM.I suppose OpenVMS does not support fork().

Looking forward for your help....
Honored Contributor

Re: equivalent of fork() in OpenVMS

There is no equivalent, or there is a direct equivalent.

Which of these two statements is true in your case depends entirely on what your code thinks fork() does.

Classic fork() isn't available, and classic fork does a whole lot more than most folks realize it does. This is less common.

The fork()/exec() model is available; see vfork() et al. This is the more common model, and use of fork() here can be replaced with vfork().

You'll want to read the C manuals as a start, as they're pretty good at describing this. And there are a couple of FAQs around for those that are familiar with C but are new to programming C on OpenVMS.

I will add a discussion of fork and vfork into that article, as I see I've omitted that.

Hein van den Heuvel
Honored Contributor

Re: equivalent of fork() in OpenVMS

What Hoff says...

Is this new code? Is there a portability requirement?

Why/What are you trying to fork?
Trying to get more threads?
Just trying to execute a (system) command?

OpenVMS offers alternative (and some times better) solutions for both, but it would have been nice to have a real fork with memory and file handle cloning and all.

Anyway... check out LIB$SPAWN when the call frequency is not crazy crazy (no more than once/second?)

And.. look around whether the task to be spawned is not available as a calleable service in the current image/process context.
OpenVMS has callable functions to find files, conver file, manipulates queue, get device information and on and on.

Welcome to OpenVMS and
Good Luck!

Honored Contributor

Re: equivalent of fork() in OpenVMS

If this is new code and not a port, then the other fairly widespread call used for creating a "child process" (usually a "subprocess" in OpenVMS terminology) is system(), BTW.

The system() call is the portable and mostly-analog version of lib$spawn or sys$creprc calls.

And while system() itself is portable C, the spawned command often isn't.

The fork() call is a subtle and extremely powerful call, and one best avoided. Unless you need its full magics, of course, and assuming you're on a box that has the full-power fork().
Frequent Advisor

Re: equivalent of fork() in OpenVMS

There is a nice example in the "ask the wizard archive":