system with several interactive programs

A

Allan Adler

In C, I can execute

system("gs gleep.ps");

and have C run a ghostscript program gleep.ps, which might ask for user
input and, when it gets it, take some actions and report back to the
C program. I think I can probably handle that last step by having ghostscript
write to a file and have the C program read the file.

That's ok for one interactive program. Suppose I want to have two or more
interactive programs running, along with possible interactive stuff done by
the C program itself. If I just execute a system command for each one, the
C program won't move past that system command until the program called by
that system command has terminated. How do I get it to start one program P1,
remain in communication with it, start another P2, remain in communication
with it, and meanwhile do its own thing which might also include asking
the user to do things and waiting for answers from the user?

My guess is that this has something to do with exec or execve, and maybe
with fork, and maybe with throw and catch and with message passing, stuff
that I've never understood and never used. What should I be reading that
explains what I need to know for this in words of one syllable.

I'm actually doing this under RedHat Linux, but since ANSI C is supposed to
be reasonably platform independent, that probably doesn't matter except in
the way that the calls are made to the operating system. The relevant concepts
and broad format should be pretty much the same, I would guess.

Here is a very concrete example. I want to have the C program run a
ghostscript program gleep.ps and a Maxima program gleep.mac and to remain
in communication with both of them them until they exit. How do I do that?
 
J

Jack Klein

In C, I can execute

system("gs gleep.ps");

Indeed you can, and it might well do something that you want done on
your system. While the system() function is part of the standard C
library, the argument you pass to it and the results are completely
implementation-defined.
and have C run a ghostscript program gleep.ps, which might ask for user
input and, when it gets it, take some actions and report back to the
C program. I think I can probably handle that last step by having ghostscript
write to a file and have the C program read the file.

That's the only portable way to do it.

That's ok for one interactive program. Suppose I want to have two or more
interactive programs running, along with possible interactive stuff done by
the C program itself. If I just execute a system command for each one, the
C program won't move past that system command until the program called by
that system command has terminated. How do I get it to start one program P1,
remain in communication with it, start another P2, remain in communication
with it, and meanwhile do its own thing which might also include asking
the user to do things and waiting for answers from the user?

Now you have passed beyond the boundaries offered by the standard C
language and library. Assuming that your platform supports concurrent
execution of multiple programs, an assumption that C does not make,
then you need to make use of extended features provided by your
platform.
My guess is that this has something to do with exec or execve, and maybe
with fork, and maybe with throw and catch and with message passing, stuff
that I've never understood and never used. What should I be reading that
explains what I need to know for this in words of one syllable.

It might well have something to do with exec, ecexve, or fork, but
none of these are part of standard C. They are extensions on some
platforms, perhaps including yours.
I'm actually doing this under RedHat Linux, but since ANSI C is supposed to
be reasonably platform independent, that probably doesn't matter except in
the way that the calls are made to the operating system. The relevant concepts
and broad format should be pretty much the same, I would guess.

ISO C (ANSI is one of the national member bodies of ISO) is indeed
reasonably platform independent, but not in the way that you think. C
has no support at all for multiple processes or threads of execution.
The chip in your microwave oven doesn't provide such things.
Here is a very concrete example. I want to have the C program run a
ghostscript program gleep.ps and a Maxima program gleep.mac and to remain
in communication with both of them them until they exit. How do I do that?

There is no way at all to do what you want in standard, that is
ISO/ANSI C. There is certainly a way that you can do it in Linux, but
platform specific extensions are not discussed here.

If you post this for the experts to see in
I'm sure they'll be happy to help
you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top