By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,417 Members | 1,845 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,417 IT Pros & Developers. It's quick & easy.

system with several interactive programs

P: n/a

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?
--
Ignorantly,
Allan Adler <ar*@zurich.csail.mit.edu>
* Disclaimer: I am a guest and *not* a member of the MIT CSAIL. My actions and
* comments do not reflect in any way on MIT. Also, I am nowhere near Boston.
Nov 14 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 04 Apr 2005 22:08:11 -0400, Allan Adler <ar*@nestle.csail.mit.edu>
wrote in comp.lang.c:

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
news:comp.os.linux.development.apps, I'm sure they'll be happy to help
you.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #2

P: n/a

Thanks to Jack Klein <ja*******@spamcop.net> for his helpful comments
in reply to my ignorant questions.
If you post this for the experts to see in
news:comp.os.linux.development.apps, I'm sure they'll be happy to help
you.


Thanks, I'll go there.
--
Ignorantly,
Allan Adler <ar*@zurich.csail.mit.edu>
* Disclaimer: I am a guest and *not* a member of the MIT CSAIL. My actions and
* comments do not reflect in any way on MIT. Also, I am nowhere near Boston.
Nov 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.