Professional Web Applications Themes

child processes - UNIX Programming

hello all, I am working on Sparc OS version 5.8. I have a code which is sth like while(i < N) { ... do some processing in c++ to create file abc system("simulator_name < abc") .....c++ ... processing...... } The problem is my simulator takes some time T to load and only then starts working on the file abc.After completion the simulator is exited and the same thing(loading + execution happens in next iterations..) Since the number of iterations are huge (wasted time NT) i want something like : open the simulator only once( just doing system("simulator_name") and get the ...

  1. #1

    Default child processes

    hello all,
    I am working on Sparc OS version 5.8. I have a code which is sth like

    while(i < N)
    {
    ...
    do some processing in c++ to create file abc
    system("simulator_name < abc")
    .....c++ ... processing......
    }
    The problem is my simulator takes some time T to load and only then
    starts working on the file abc.After completion the simulator is
    exited and the same thing(loading + execution happens in next
    iterations..) Since the number of iterations are huge (wasted time NT)
    i want something like :

    open the simulator only once( just doing system("simulator_name") and
    get the handle to the simulator prompt. From then on i just load the
    new "abc" file in each iteration, wait for the simulation to complete
    (do not exit the simulator) and start my new iteration.

    I read about creating a new child process(popen command) etc but could
    not figure out exactly how to get a handle to the prompt, and wait
    till the simulation is completed. Also the child process is not to be
    killed otherwise i lose the handle.
    I would appreciate any help/references in this regard. There is
    nothing simulator specific. You can imagine a simple gdb command in
    place of simulator_command and handle at gdb>

    -Thanks
    Vikas
    Vikas Vijay Guest

  2. #2

    Default Re: child processes

    * [email]vijayvececs.uc.edu[/email] (Vikas Vijay)
    | I read about creating a new child process(popen command) etc but
    | could not figure out exactly how to get a handle to the prompt, and
    | wait till the simulation is completed.

    popen() returns a FILE*, which you can use in an fprintf()/fwrite()
    call. It is connected to the stdin of the popen'ed() process. So the
    solution would be to make your process read commands from stdin (which
    it presumably already does when it prompts), process them and read the
    next command.

    If you need feedback when the processing is finished, you might use
    some statefile which the parent creates and the simulator removes to
    indicate finish (eg, the `abc' file in your example).

    popen() is unidirectional (read/write only), so if you need something
    more sophisticated, you need to check the IPC features of your OS
    (pipes, shared memory).

    R'
    Ralf Fassel Guest

  3. #3

    Default Re: child processes


    "Vikas Vijay" <vijayvececs.uc.edu> wrote in message
    news:ce59d7c6.0307200656.13a98c31posting.google.c om...
    > hello all,
    > I am working on Sparc OS version 5.8. I have a code which is sth like
    >
    ------start the simulator here and open a pipe to its standatad input.
    > while(i < N)
    > {
    > ...
    > do some processing in c++ to create file abc
    ------send the files contents to the pipe
    ------// note 'if this code worked, your simulator exits each time it
    reads ------a file. so you need to change it to continue receiving file
    names and ------may be an exit command in the end.
    > system("simulator_name < abc")
    > .....c++ ... processing......
    > }
    ------exit the simulator
    > The problem is my simulator takes some time T to load and only then
    > starts working on the file abc.After completion the simulator is
    > exited and the same thing(loading + execution happens in next
    > iterations..) Since the number of iterations are huge (wasted time NT)
    > i want something like :
    >
    > open the simulator only once( just doing system("simulator_name") and
    > get the handle to the simulator prompt. From then on i just load the
    > new "abc" file in each iteration, wait for the simulation to complete
    > (do not exit the simulator) and start my new iteration.
    >
    > I read about creating a new child process(popen command) etc but could
    > not figure out exactly how to get a handle to the prompt, and wait
    > till the simulation is completed. Also the child process is not to be
    > killed otherwise i lose the handle.
    > I would appreciate any help/references in this regard. There is
    > nothing simulator specific. You can imagine a simple gdb command in
    > place of simulator_command and handle at gdb>
    >
    > -Thanks
    > Vikas

    nal Guest

Similar Threads

  1. Parent/Child relations - Trying to access child control for save
    By tnt_lu@hotmail.com in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: April 15th, 12:50 PM
  2. Placeholder child of child control event problem.
    By caldera in forum ASP.NET Building Controls
    Replies: 1
    Last Post: May 28th, 07:56 AM
  3. Timing several processes
    By Anthony Akens in forum PERL Beginners
    Replies: 13
    Last Post: December 4th, 02:00 PM
  4. Limiting child processes in a sub-shell
    By Peter in forum Sun Solaris
    Replies: 0
    Last Post: July 3rd, 02:22 AM
  5. Managing linked list through child processes
    By Barry Margolin in forum UNIX Programming
    Replies: 0
    Last Post: June 30th, 05:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139