Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4610112
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:05:07+00:00 2026-05-22T01:05:07+00:00

I have managed to fork and exec a different program from within my app.

  • 0

I have managed to fork and exec a different program from within my app. I’m currently working on how to wait until the process called from exec returns a result through a pipe or stdout. However, can I have a group of processes using a single fork, or do I have to fork many times and call the same program again? Can I get a PID for each different process ? I want my app to call the same program I’m currently calling many times but with different parameters: I want a group of 8 processes of the same program running and returning results via pipes. Can someone please point me to the right direction please ? I’ve gone through the linux.die man pages, but they are quite spartan and cryptic in their description. Is there an ebook or pdf I can find for detailed information ? Thank you!

pid_t pID = fork();
 if (pID == 0){
  int proc = execl(BOLDAGENT,BOLDAGENT,"-u","2","-c","walkevo.xml",NULL);
  std::cout << strerror(errno) << std::endl;
}

For example, how can I control by PID which child (according to the parameter xml file) has obtained which result (by pipe or stdout), and thus act accordingly? Do I have to encapsulate children processes in an object, and work from there, or can I group them altogether?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:05:07+00:00Added an answer on May 22, 2026 at 1:05 am

    One Fork syscall make only one new process (one PID). You should organize some data structures (e.g. array of pids, array of parent’s ends of pipes, etc), do 8 fork from main program (every child will do exec) and then wait for childs.

    After each fork() it will return you a PID of child. You can store this pid and associated information like this:

    #define MAX_CHILD=8
    pid_t pids[MAX_CHILD];
    int pipe_fd[MAX_CHILD];
    for(int child=0;child<MAX_CHILD;child++) {
     int pipe[2];
     /* create a pipe; save one of pipe fd to the pipe_fd[child] */
     int ret;
     ret = fork();
     if(ret) { /* parent */ 
      /* close alien half of pipe */
      pids[child] = ret; /* save the pid */
     } else { /* child */
      /* close alien half of pipe */
      /* We are child #child, exec needed program */
      exec(...);
      /* here can be no more code in the child, as `exec` will not return if there is no error! */
     }
    } 
    
    /* there you can do a `select` to wait data from several pipes; select will give you number of fd with data waiting, you can find a pid from two arrays */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a C++ task that will fork a new process. That process in
i have managed to get my app to email a copy of its database
I have managed to implement a very basic PDF viewer within my application, but
i have managed to connect to an interbase database and get data from the
If I have managed to locate and verify the existence of a file using
I have installed Delphi Prism and XNA Game Studio 3.0. I have managed to
I've deconstructed a standard WPF button using Blend and have managed to create a
At work I work closely with MS-Office. I have managed to generate some scripts
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have a managed dll that calls into a native library. This native library

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.