child process to run in its own shell script?

This is a discussion on child process to run in its own shell script? within the C Programming forums, part of the General Programming Boards category; I have the parent process doing some computation that involves outputting a lot of stuff to the terminal, and I ...

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    8

    child process to run in its own shell script?

    I have the parent process doing some computation that involves outputting a lot of stuff to the terminal, and I have another portion of code that I would like to run in its own terminal, as this portion uses both stdin and stdout (it's basically just a while loop with a prompt).

    Initially, I thought to have the second portion run as an argument to gnome-terminal.


    From what I've read online, it seems the only way to do this would be to write the while loop function as a shell script, then use the export switch to run it; sadly, I don't know sh atm, so is there any way to specify the function name as an arg to gnome-terminal?

    I would like to be able to do something like the following:

    Code:
    int otherFunction(...) {
      /*while loop with prompt*/
    }
    
    
    int main() {
      if (!fork()) { /*child*/    
        system("gnome-terminal -x \"otherFunction(...)\");
      } else { /*parent*/
        /*do other stuff*/
        }

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    your problem with this approach is that the two terminals will run in different processes so even though you could manage to link to the exported function in the executable (possible but complicated) they would be isolated from each other by default. what you really want is two separate processes, each started in its own terminal then communicating using one of the interprocess communication mechanisms. shared memory, pipes etc. you certainly could have a single executable that accepts an argument that tells it what to run.

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    8
    thanks for your quick response, dmh2000.

    So an example implementation of what you're proposing, then, would involve a parent forking off two child processes, who each have their respective terminals and can communicate through piping, if I understand your response correctly. So then, aren't I still left with the problem of how I pass a function to gnome-terminal?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. create a child process that creates a child process
    By cus in forum Linux Programming
    Replies: 9
    Last Post: 01-13-2009, 01:14 PM
  2. Shell script
    By diamond in forum Linux Programming
    Replies: 5
    Last Post: 03-26-2004, 07:39 AM
  3. shell script
    By duffy in forum Tech Board
    Replies: 1
    Last Post: 10-24-2002, 05:15 PM
  4. Child Process & Parent Process Data :: Win32
    By kuphryn in forum Windows Programming
    Replies: 5
    Last Post: 09-11-2002, 12:19 PM
  5. Really need help for this C shell script
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-22-2002, 04:39 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21