HP OpenVMS Systems

ask the wizard
Content starts here

lib$spawn, sys$creprc, mailboxes?

» close window

The Question is:

I'm having great difficulty understanding and using the SYS$CREPRC and
 LIB$SPAWN facilities. I understand that if I want to spawn off processes when
 the main process is detached, I need to use SYS$CREPRC. But I don't fully
 understand the behavior I'm seei
 For most of the I/O I'm using the POSIX calls (open(), read(), write()). An
 outline of the basic procedure I'm using:
1. Create temporary mailboxes for SYS$INPUT and SYS$OUTPUT with SYS$CREMBX.
2. Run SYS$CREPRC, using image LOGINOUT and the mailboxes just created.
3. Open() a command file, read() it to a buffer.
4. Open the mailbox using the iochannel and the POSIX open() call.
5. Write() the command buffer to the input mailbox.
6. Close() the command file and the input mailbox.
7. Open() the output mailbox, read() the results.
 The call to read() hangs at the end of the
script output, I never get an EOF.
 If, instead of reading the command (e.g. "testscript.com") into a buffer, I
 write a command to the input mailbox like "spawn @testscript", I *can* get it
 to complete. However, I get one EOF for the script output, then I have to read
 to the second EOF
to get the message "%DCL-S-RETURNED, control returned to process". Only then
 will the child process actually go away.
 I'd like to avoid the "spawn @" method - so far as I can tell this just
 creates an extra process that shouldn't be needed. Any suggestions?

The Answer is :

  The lib$spawn call is a special case of sys$creprc, and propogates the
  environment (symbols and logical names) from the parent process into
  the created subprocess.  Unlike the sys$creprc system service, the
  lib$spawn RTL call requires a command language interpreter (typically
  DCL) be present in the process that issues the request.
  The OpenVMS Wizard will assume you are not using the POSIX package, but
  are using typical ANSI C library routines.
  The OpenVMS Wizard would encourage direct $qio to the mailbox devices,
  rather than layering additional file-oriented I/O semantics onto the
  communications between the processes.  Details on the specific source
  code used here -- a reproducer -- would be interesting.
  The OpenVMS Wizard would also strongly recommend specification of the
  complete list of process quotas.
  A complete example of detached processes and mailbox communications (via
  $qio) is included in the [SRH_EXAMPLES]MBXDEMO.C file on the OpenVMS
  Freeware V4.0 CD-ROM.
  Other areas of interest -- depending on the particular sequence of C
  code involved -- might include the DECC$MAILBOX_CTX_STM logical name,
  documented with recent versions of the Compaq C compiler.

answer written or last revised on ( 28-FEB-2001 )

» close window