From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,aba62ded60e0d703 X-Google-Attributes: gid103376,public From: dennison@telepath.com Subject: Re: Spawning a subprocess and communicating with it. Date: 1998/10/02 Message-ID: <6v2rla$e19$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 397052850 References: X-Http-Proxy: 1.0 x2.dejanews.com:80 (Squid/1.1.22) for client 204.48.27.130 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Fri Oct 02 15:31:53 1998 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.05 [en] (WinNT; I) Date: 1998-10-02T00:00:00+00:00 List-Id: In article , "Condic, Marin D." 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: ), 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