system with several interactive programs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Allan Adler

    system with several interactive programs


    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 <ara@zurich.csa il.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.
  • Jack Klein

    #2
    Re: system with several interactive programs

    On 04 Apr 2005 22:08:11 -0400, Allan Adler <ara@nestle.csa il.mit.edu>
    wrote in comp.lang.c:
    [color=blue]
    >
    > In C, I can execute
    >
    > system("gs gleep.ps");[/color]

    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.
    [color=blue]
    > 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.[/color]

    That's the only portable way to do it.

    [color=blue]
    > 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?[/color]

    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.
    [color=blue]
    > 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.[/color]

    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.
    [color=blue]
    > 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.[/color]

    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.
    [color=blue]
    > 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?[/color]

    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.li nux.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.l earn.c-c++

    Comment

    • Allan Adler

      #3
      Re: system with several interactive programs


      Thanks to Jack Klein <jackklein@spam cop.net> for his helpful comments
      in reply to my ignorant questions.
      [color=blue]
      > If you post this for the experts to see in
      > news:comp.os.li nux.development .apps, I'm sure they'll be happy to help
      > you.[/color]

      Thanks, I'll go there.
      --
      Ignorantly,
      Allan Adler <ara@zurich.csa il.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.

      Comment

      Working...