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

  • SEARCH
  • Home
  • 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 8455039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:11:01+00:00 2026-06-10T12:11:01+00:00

I have two executables – parent process and it’s child process, running in a

  • 0

I have two executables – parent process and it’s child process, running in a long mode (for example server etc). All I need is to redirect child’s stdout and stderr to parent’s process and write them to file or print to tty, don’t matter now.

This is pretty straightforward task if we talking about simple child, but with long-running child with partial outputting it is a problem.

For example let’s look at popular solution with usage of pipe (error checking and other non-important parts omitted):

parent.c

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main(int argc, const char *argv[])
{
  int link[2];
  pid_t pid;
  char str[4096];

  pipe(link);
  pid = fork();

  if (pid == 0) {
    dup2(link[1], STDOUT_FILENO);
    close(link[0]);
    execl("/path_to_bin/fast_child", "fast_child", (char *)0);
  }
  else 
  {
    close(link[1]);
    read(link[0], str, sizeof(str));
    printf("Pipe contents: %s\n", str);
    wait(NULL);
  }

  return 0;
}

fast_child.c

#include <stdio.h>
#include <unistd.h>

int main(int argc, const char *argv[])
{
  printf("I'm fast child\n");
  return 0;
}

Using this type of child process in excellent and non-problematic way to get str(out|err) in parent, but using this code as child cause problems of output disappearing in parent:

slow_child.c

#include <stdio.h>
#include <unistd.h>

int main(int argc, const char *argv[])
{
  for (;;)
  {
    printf("I'm slow child\n");
    sleep(1);
  }
  return 0;
}

I’m thinking about socket usage as problem solving solution but I’m sure that this is not so efficient way and Unix provides better tools to do this (as usual 🙂

Thank you.

  • 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-06-10T12:11:02+00:00Added an answer on June 10, 2026 at 12:11 pm

    You need to flush your output from the child every now and then or the parent task won’t see anything. use fflush(stdout) at appropriate points. Or you could switch off the buffering on stdout, but that might have a performance impact on your child, as it will do a system call on each character written.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two files client.php and server.php. The client file send a HTTP request
I have a common library and two executables. Each executable refers to the common
I have been using Process.Start to launch executables (.exe) files. Now I need to
I have two executables that reference the same Class Library. In the class library
I have got two different executables written in Delphi 6. I am in the
I have a visual c# project from which I want to compile two executables:
I have two executables that access a DLL containing Data Access Layer objects Each
I have installed vim in my computer, and i see there are two executables
Have two folders with approx. 150 java property files. In a shell script, how
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two

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.