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 8772859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:08:23+00:00 2026-06-13T18:08:23+00:00

I spawn a child process using pipe(), fork(), dup(), execve(). From the parent, is

  • 0

I spawn a child process using pipe(), fork(), dup(), execve().

From the parent, is it safe to wait for stdin and stdout of the child to close (i.e. read() return 0 on both), and then do waitpid() to collect the termination status?

Or can it happen that the process will fail without ever closing stdin and stdout? (thus my program never getting to waitpid)


To clarify, I’m asking whether the following is safe:

while (child_stdin != -1 && child_stdout != -1) {
    poll(...)

    if (got_stdout) {
        n = read(child_stdout);
        if (n >= 0) {
            // do something with output
        } else if (n == 0) {
            child_stdout = -1
        }
    }

    // same for stdin
}

waitpid(child_pid)

Or can it happen that child will terminate, but I’ll never get 0 on read() or write().

No signals are involved, just poll()-ing.

  • 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-13T18:08:25+00:00Added an answer on June 13, 2026 at 6:08 pm

    If process a spawns process b, and process b spawns process c (so c is the grandchild of a), b can terminate and close its copy of the file descriptor that was its stdout (presumably, b's stdout is the write side of a pipe that a is watching.) But c still has that pipe open, so a will get the SIGCHLD from b, but will not get EOF on the pipe. In other words, yes, it can happen that the child terminates but the parent does not see the pipe close.

    Also, it is a common coding error that a still has the write side of the pipe open. In that case, b can terminate and close its copy of the write side of the pipe, but the parent never sees the pipe close because the parent is keeping it open.

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

Sidebar

Related Questions

I'm using child_process.spawn/child_process.fork to start a number of child processes from a node.js application.
I'm trying to spawn a new process from my C++-project using fork-exec. I'm using
I'm using node.js to spawn a child process and consume its output, using the
If you spawn a child process in ruby (using Kernel.system for example), can it
I use posix_spawnp to spawn child processes from my main process. int iRet =
I would like to spawn a Windows form from the console using C#. Roughly
I am trying to spawn a process using Runtime.exec. I want to use my
I'd like to spawn several graphics windows from within a function in R using
My Windows XP/7 program launches a child process using the Windows API CreateProcess() function
My python code spawns the child process, and it prints out messages both stdout

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.