Operating System - OpenVMS
1753797 Members
6951 Online
108799 Solutions
New Discussion юеВ

How to Share the variable between two .exe's [ compaq C on VMS]

 
how to create batich qu
Occasional Contributor

How to Share the variable between two .exe's [ compaq C on VMS]

Hi,

Please explain how the Globaldef & globalref will work?

I need to define a variable which can share between [globally ] two exe's in Compaq C on VMS.

I heard about globaldef and globalref for defining a variable globally & using it.
But im not able to share this variable
with "two different executables."

Please reply me if you have any idea on this.

Byebye
Ramesh
13 REPLIES 13
Kris Clippeleyr
Honored Contributor

Re: How to Share the variable between two .exe's [ compaq C on VMS]

Ramesh,
Share a variable betzeen two exe's?
Do you mean two different programs running in the context of two different processes?
If so, an option would be to use the system services $CRMPSC and $MGBLSC.
The "globaldef/globalref" constructs are used to declare variables globally to your program, their scope does not extend beyond the program.
Regards,
Kris (aka Qkcl)
I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
how to create batich qu
Occasional Contributor

Re: How to Share the variable between two .exe's [ compaq C on VMS]

Hi Kris,

Yes. share the variables between two exe's.
Yes. Two different programs running in the two diffreent executables.


can you tell me more on this $CRMPSC and $MGBLSC and how it will work if you know.

[or] Is there any other way?

Thanks for your reply.

Bye
Ramesh
Robert Gezelter
Honored Contributor

Re: How to Share the variable between two .exe's [ compaq C on VMS]

Ramesh,

Describing CRPMSC and MPGBLSC are both fully documented in the "OpenVMS System Services Reference Manual" and the "Programming Concepts Manual", both of which are available online via the documentation section of the OpenVMS www site at http://www.hp.com/go/OpenVMS

I would rather that you review the documentation in depth before using them. Personally, I have seen more problems caused by sharing variables between programs, particularly in multi-processor contexts, which are now common, than I care to think about.

Sharing variables between two (or more) programs in different executables safely requires extremely carefully thought out safety precautions. Use of the Lock Manager or proper semaphores is critical. There are also issues of propagating problems from one user to another.

Personally, in almost all cases, I have found it sufficiently efficient to use a variety of techniques including: Lock Manager values, DECnet logical links, TCP/IP pipes, and other mechanisms to pass data between cooperating processes in total safety, without having to resort to the hazards of direct sharing of memory locations.

- Bob Gezelter, http://www.rlgsc.com
Hein van den Heuvel
Honored Contributor

Re: How to Share the variable between two .exe's [ compaq C on VMS]

$CRMPSC and friends allow for DYNAMIC sharing of a piece of memory. Typically it would NOT involve globalref/globaldef but a common structure defintion and relative addressing.

The more classic/easy way for two executables (A, B) to share data is to use a third one (C) "Common" with just data in a shareable image created with LINK/SHARE. This is all well documented in the OpenVMS concepts, language users guides and Linker reference manual.

hth,
Hein.

Robert Gezelter
Honored Contributor

Re: How to Share the variable between two .exe's [ compaq C on VMS]

Ramesh,

While I was directly responding to Kris' comment, Hein is correct. However, the issues that I view as a concern are just as applicable to the static sharing through the use of the LINKER as to the dynamic sharing facilitated by mapping the section dynamically.

In both cases, extreme care must be exercised to prevent errors, and these errors are subtle and difficult to reliably detect. I have seen far too many cases where these problems survived for many, many years, occasionally appearing and just as quickly disappearing, until somebody by chance realized what the problem is.

I always recommend that clients use other alternatives (as noted) before resorting to memory sharing between processes. In almost every case that I have had to explore, the "efficiency" savings of shared memory are insufficient performance gains when compared to the costs of developing and debugging the code.

- Bob Gezelter, http://www.rlgsc.com
how to create batich qu
Occasional Contributor

Re: How to Share the variable between two .exe's [ compaq C on VMS]

Hi All,

Thanks for your reply.

I think you people have reached greater extend level.

But, i just need to set a flag by one variable in one EXE. And this flag is taken by the another EXE.

So please provide your suggestions on this.

bye
Ramesh
Kris Clippeleyr
Honored Contributor

Re: How to Share the variable between two .exe's [ compaq C on VMS]

Ramesh,

> But, i just need to set a flag by one
> variable in one EXE. And this flag is
> taken by the another EXE.

This sounds like inter-process synchronization.

There are a number of techniques available under VMS (as my learned colleagues have pointed out). You can use the lock manager, common event flags, logical names, mailboxes.
Please see the programming concepts manual at:
http://h71000.www7.hp.com/doc/82FINAL/5841/5841PRO.HTML

Regards,
Kris (aka Qkcl)


I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
Hein van den Heuvel
Honored Contributor

Re: How to Share the variable between two .exe's [ compaq C on VMS]

>> But, i just need to set a flag by one variable in one EXE. And this flag is taken by the another EXE.

So what problem do you really want to solve.
What's the flag going to do.

Should it interrupt or will it be polled?

For polling...

The 'classic' solution to set a flag in an other process is to use a COMMON EVENT FLAG CLUSTER. Check out the same concepts manual again, or the SYSTEM SERVICE REFERENCE MANUAL. For a sneak preview: $HELP SYSTEM $ASCEFN

LOCKs can be used both for polling and interrupst. Check out BLOCKING AST's.

Ditto for MAILBOX IOs. You can poll with QIO IO$M_NOW to see if there is a 'command' or set up a WRITE ATTENTION AST.

Important questions to consider
- Will those processes share the same GROUP or will they be WORLD to each other?
- Are those images in the SAME JOB? (sharing a job logical name table?
- Security / Privs available?

Many more alternatives for polling are LOGICAL NAMES.

Or, here is a cute one... process names.
The first image could call itself "Hey you: GO" and chage that to "Hey you:STOP" as needed. The second image could poll that.

btw.. if the reall proble you are trying to solve is a stop/go issue, then the ideal communication is the system service combo $HIBER/$WAKE

Hope this helps some,
Hein van den Heuvel (at gmail dot com)
HvdH Performance Consulting




Hein van den Heuvel
Honored Contributor

Re: How to Share the variable between two .exe's [ compaq C on VMS]

Bob wrote> While I was directly responding to Kris' comment, Hein is correct. However, the issues that I view as a concern are just as applicable to the static sharing

And I failed to start asking my normal opener 'what problem are you really trying to solve'. Judging by the follow up, Bob rightly pointed to several interprocess communication techniques in anticipation of the underlying problem.

btw... we didn't really answer the actuall question asked even though that might not solve the real problem:

>> Please explain how the Globaldef & globalref will work?

Typically it works between two modules in a single executable, or a shareable (image) module defining the images and other moduleing linking against that.
One source module, defines a variable and and other indicates it wants to use it. The compiler can NOT resolve that, only carry it forward as a request in the Object it produces. It is the LINKER which resolves the globalref, 'seeing' the globaldef from the other module.

Cheers,
Hein.