HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

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
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
Alex Chupahin
Super Advisor

Re: Process mailbox usage simple question

Good, I should read example6 for answer.
I started example6 together with example5 and it just worked.

Anybody wish to know mailboxes and reading this thread, do not make a mistake like me:
1. do not forget about differences between QIO and QIOW;
2. do not forget VMS mailboxes are not a real *mail boxes* and have no cache or buffer. To be able to put anything in immediate mode via QIOW to mailbox you should be sure there is a process that reading from mailbox.
Brian Reiter
Valued Contributor

Re: Process mailbox usage simple question

Or use the flags

IO$_WRITEVBLK
IO$M_NOW
IO$M_NORSWAIT

Which our systems have used since the early 90s (and still use).

cheers

Brian
Hoff
Honored Contributor

Re: Process mailbox usage simple question

>1. do not forget about differences between QIO and QIOW;

Asynchronous versus synchronous I/O is a significant difference, yes.

2. do not forget VMS mailboxes are not a real *mail boxes* and have no cache or buffer.

False. OpenVMS mailboxes DO have caching. That's what you set with the quotas.

>To be able to put anything in immediate mode via QIOW to mailbox you should be sure there is a process that reading from mailbox

Actually, you CAN use the synchronous form with an immediate completion flag on the sys$qiow.

OpenVMS is increasingly written in C, which isn't the newest language. Of the older code, that's roughly equally split between Bliss and Macro32.

Both Bliss and C are well-suited to low-level application and OS work, but not without the various and unique weirdness that will be found in each. Both are comparatively old languages.

Read the I/O user's manual, too, while you're reading the manuals. That manual describes how mailboxes work, and it is a good bet that most folks don't understand that.

There are features in mailboxes that I would never recommend using; there are features you think you want to use and that lead to pain and grief. Here are some tips I posted last year: http://64.223.189.234/node/250
Alex Chupahin
Super Advisor

Re: Process mailbox usage simple question

I find why example5 is freezing:
IO$M_NOW
should be added to SYS$QIOW() call
to get behavor identical there.
BTW it is mistake in manual ;)