comp.lang.ada
 help / color / mirror / Atom feed
From: dennison@telepath.com
Subject: Re: Spawning a subprocess and communicating with it.
Date: 1998/10/02
Date: 1998-10-02T00:00:00+00:00	[thread overview]
Message-ID: <6v2rla$e19$1@nnrp1.dejanews.com> (raw)
In-Reply-To: F3740247C2BED111A0AE00805FEA9C92017FFD15@pwflml02.pwfl.com

In article <F3740247C2BED111A0AE00805FEA9C92017FFD15@pwflml02.pwfl.com>,
  "Condic, Marin D." <condicma@PWFL.COM> wrote:
>     I want to write an Ada program that can start up another Ada
>     program as a subprocess, coprocess or whatever is the common Unix
>     paradigm. (I just need it running as a separate, stand-alone
>     executable image whose execution need go on no longer than that of
>     the parent program that initiated it.) When the subprocess is up
>     and running, I need to trade messages back and forth (character
>     strings are sufficient) between the two processes.
>
>     I presume this is all doable through various Unix system calls,
>     but unfortunately, we don't seem to have anyone around here who is
>     much of an expert on Unix calls, or how to interface to them via
>     Ada or even any manuals one might peruse on the subject. If
>     someone could send me a small example of how this is done, I would
>     be grateful. Thanks.

I highly suggest you get hold of such a person if this is truly what you want
to do. If *you* want to become such a person, go to your local library and
get a good Unix systems programming book. If you are handy with "man" you can
try to figure it out from there as well.

I can't provide an example (I changed jobs 4 months ago, and don't have any of
my old code around), but I can tell you what system calls you need to use:

For process creation, the standard method is the following kludge:
  1.  Make a call to the system routine "fork"
  2.  If the return value is 0, call the "exec" system routine with the
(C string) file path name of the other program you want to run.

A slightly prettier method is to make a call to the highly useful "system"
system routine with the (C string) shell command that will run your other Ada
program in the background. If you don't end the command with an "&", then
your calling program will wait for the new program to terminate. This is
essentially the same as the above two steps, with the extra hidden steps of
starting up a shell and a third temporary process.

 The Unix calls for interprocess communication would be "shmget" followed by
"shmat" for a shared-memory based interface or "msgget", "msgsnd" and "msgrcv"
for a message passing interface. The "Key" these routines require is just some
arbitrary number that has to match between the processes (and shouldn't match
anyone else's!).

As for how to interface to the system calls, its really quite simple. Most
compilers come with bindings, but I usually make my own anyway. Its the same
as interfacing to any other C code. The man pages for the calls will tell you
which ".h" files to look in for the definitions of the calls and the types
they use. If the file name is enclosed in "<>", (eg: <unistd.h>), look for
the file in /usr/include. The name of the C library you have to link in is
probably also spelled out in the man page. For libraries, "<>" means look in
/usr/lib.

I hope this was of some small help.

--
T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




  parent reply	other threads:[~1998-10-02  0:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-10-01  0:00 Spawning a subprocess and communicating with it Condic, Marin D.
1998-10-02  0:00 ` Rick Stikkers
1998-10-02  0:00 ` dennison [this message]
1998-10-05  0:00 ` John McCabe
1998-10-12  0:00 ` Tom Moran
  -- strict thread matches above, loose matches on Subject: below --
1998-10-05  0:00 Condic, Marin D.
1998-10-06  0:00 ` dennison
1998-10-06  0:00 ` Robert L. Spooner
1998-10-07  0:00 ` John McCabe
1998-10-08  0:00   ` dennison
1998-10-07  0:00 ` Jerry van Dijk
1998-10-07  0:00 Condic, Marin D.
1998-10-08  0:00 ` dennison
1998-10-08  0:00 ` Jerry van Dijk
1998-10-08  0:00 ` dennison
1998-10-08  0:00 Condic, Marin D.
1998-10-09  0:00 ` alan walkington
1998-10-09  0:00 Condic, Marin D.
1998-10-13  0:00 ` Robert I. Eachus
1998-10-09  0:00 Condic, Marin D.
1998-10-12  0:00 Condic, Marin D.
1998-10-13  0:00 ` Pascal Obry
1998-10-13  0:00 Condic, Marin D.
1998-10-13  0:00 ` Scott Ingram
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox