Operating System - OpenVMS
1753835 Members
7659 Online
108806 Solutions
New Discussion юеВ

Process mailbox usage simple question

 
SOLVED
Go to solution
Alex Chupahin
Super Advisor

Process mailbox usage simple question

Hello,

I'm reading Mailbox SYS routines documentation
regard to synchronious I/O (to use standard I/O stream routines)
http://h30266.www3.hp.com/odl/vax/opsys/vmsos73/vmsos73/5841/5841pro_007.html
for example
and do not understand simple things.

I just translate 2 simple programs published at the doc from Fortran to C and wish it communicable

/* MAIN: */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

main()
{
int stat_R0;
int mbx_chan;
FILE *M;
char s[1024];

$DESCRIPTOR( MBX_NAME, "MAIL_BOX" );
$DESCRIPTOR( SUBPROC, "RU SUBPROCESS.EXE");

stat_R0 = SYS$CREMBX (0,&mbx_chan,
NULL,NULL,NULL,NULL,
&MBX_NAME);
if((stat_R0 & 1) != 1)
LIB$SIGNAL(stat_R0);


if ( (M=fopen("MAIL_BOX","w+"))==NULL )
perror("cant fopen mailbox\n");
stat_R0 = LIB$SPAWN ( &SUBPROC );
fprintf(M,"hello\n ");
fgets(s,256,M);
if((stat_R0 & 1) != 1) perror("error spawn\n");

printf("%s\n",s);
}


/* SUBPROCESS */
#include
#include
#include
#include
#include

$DESCRIPTOR ( MBX, "MAIL_BOX" );

main()
{
int mbx_chan;
int stat_R0;
FILE *M;
char s[256];

stat_R0 = SYS$ASSIGN(&MBX,&mbx_chan,0,0);

if ( (stat_R0 & 1) != 1 )
perror("Error sys$assign\n");

if ( (M=fopen("MAIL_BOX","r+"))==NULL )
perror("get mailbox error\n");

fgets(s,255,M);
printf("read data: %s\n",s);
fprintf(M,"Answer: %s",s);

}
13 REPLIES 13
Alex Chupahin
Super Advisor

Re: Process mailbox usage simple question

When I start the main program it just freezes and do not types any text.


Hoff
Honored Contributor
Solution

Re: Process mailbox usage simple question

There is no way I'd mix C standard I/O with mailboxes.

Can it work? Sure, but OpenVMS isn't Unix and everything isn't really streams of bytes on OpenVMS; trying to get C file semantics on RMS semantics on OpenVMS file semantics onto what are really mailbox devices tends to get, um, hairy.

Here's your example program, slightly rewritten:

[broken link removed on <4/11/2017> by Mod]  


(there's a build procedure in the same directory.)

Jess Goodman
Esteemed Contributor

Re: Process mailbox usage simple question

The reason your main program freezes is that LIB$SPAWN is, by default, synchronous. The call to LIB$SPAWN will not return until the subprocess completes. To make is asynchronous use flag CLI$M_NOWAIT like this:

int flags = CLI$M_NOWAIT;
...
stat_R0 = LIB$SPAWN ( &SUBPROC, NULL, NULL, &flags );

But I agree with Hoff that using standard C I/O with mailboxes is a bad idea. By default C I/O is stream oriented and mailboxes are record oriented and these don't mix well.

You might be able to get it to work by adding , "ctx=rec" to your FOPEN calls. If you do, then you don't need to SYS$ASSIGN a channel in the subprocess - that would only be needed if you were using SYS$QIOW call to read/write data.
I have one, but it's personal.
Alex Chupahin
Super Advisor

Re: Process mailbox usage simple question

Thank you Hoff,
but can we discuss your example?
Ido not understand many things.
At MASTER mode you create mailbox named
"MBXNAM", right?

/*--- MASTER ----*/
$DESCRIPTOR( mbxnam_d, MBXNAM );

status = sys$crembx(0, &channel, MAXMBXMSG, MAXMBXBUF,
0, 0, &mbxnam_d, 0);
/* ------ */



Very good.
But for SLAVE process you opens SYS$INPUT,
attached to devnam_d that is not mailbox.
(I do not totally understand what value devnam_d is in your example, but it is a second question)

/* SLAVE */
$DESCRIPTOR( sysinp_d, "SYS$INPUT");

status = sys$assign( &sysinp_d, &channel, 0, 0, 0 );

/*--- */

Where you are reading from mailbox here ?
Alex Chupahin
Super Advisor

Re: Process mailbox usage simple question

Jess,
I added flag you pointed.
when started, I just get string "hello"
on my terminal just like it simple typed by
printf("Hello");
I do not understand how it works. :(

It seems, so many years ago I was little yunger and clear :) (I am 33 now ) and could understand documentation. I had studed RT-11,TSX and P/OS on my Russian clone of Pro-350 17 years ago without any problems. And without Internet of course ;)
Documentation was clear for me. It seems I got a foolish for years for a distance from 1995 when I begun to study unix :) or documentation now from HP is not good as was from DEC.

Volker Halle
Honored Contributor

Re: Process mailbox usage simple question

Alex,

the 'slave' process is being started with a $CREPRC system service, passing devnam_d as the SYS$INPUT file/device name. devnam_d is the descriptor for the devnam_b string, which contains the full device name of the mailbox obtained via a $GETDVIW call on the mailbox device channel.

Volker.
Alex Chupahin
Super Advisor

Re: Process mailbox usage simple question

> name of the mailbox obtained via a $GETDVIW call on the mailbox device channel

Ok, thank you.
now I understand a coupe of things...
It is interesting how MACRO concepts going to C. It is not clean sometimes ;) C is not best language for OpenVMS IMHO...

Found good thing:
http://www.openvms.compaq.com/openvms/journal/v9/mailboxes.pdf
I'm reading it...
Alex Chupahin
Super Advisor

Re: Process mailbox usage simple question

http://www.openvms.compaq.com/openvms/journal/v9/mailboxes.pdf
page 12, Example 5

Another strange thing, strange behavor
This program should read strings from console and put into mailbox. And this is *screeshot* from the article:
-----------
$ r mailbox_writer
Bruce Ellis was here
Welcome to Mailboxes from BRUDEN-OSSG
We have lot's of great guys and a great Guy on board.
Control-Z was entered on the next line.
Exit
$
-----------

I've compiled sources from the acticle, but execution freezes during SYS$QIOW call
What's happens?
Ian Miller.
Honored Contributor

Re: Process mailbox usage simple question

Do read current documentation

http://h71000.www7.hp.com/doc/732FINAL/aa-pv6sf-tk/aa-pv6sf-tk.HTMl

As some things have changed like stream I/O is now possible with mailboxes (although I don't know why).

____________________
Purely Personal Opinion