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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:39:41+00:00 2026-05-31T04:39:41+00:00

Here is a small piece of code, the parent process write pipe and child

  • 0

Here is a small piece of code, the parent process write pipe and child read pipe, everything works fine before I add ‘wait()’ in parent process. I think it should be no difference, but it just stucks when I input. I’m quite new to system programming. Anyone can help with this?

int main() {
      char* msg = malloc(sizeof(100));
      int fd[2];
      pipe(fd);
      int status;


if (fork()!=0){
    close(fd[0]);
    dup2(fd[1],1);
    scanf("%s",msg);
    puts(msg);
    wait(&status);
}
else {
    char* buf = malloc(sizeof(100));
    close(fd[1]);
    dup2(fd[0],0);
    scanf("%s",buf);
    puts(buf);
}
return 0;}
  • 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-31T04:39:43+00:00Added an answer on May 31, 2026 at 4:39 am

    You have to flush stdout before calling wait().

    Your program was working before without the wait() since an implicit flush was done when the parent process exit.

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

Sidebar

Related Questions

Here is a small currency converter piece of code: public enum CurrencyType { DOLLAR(1),
Here is a small piece of code. Posted by Russian company Yandex as a
I have a small piece of code here for your consideration which puzzles me
I have a piece of code that divides a image matrix img into small
I've been working on this small piece of code that seems trivial but still,
presently I am writing a small piece of code to get the list of
I am trying to optimize a small piece of code with SSE intrinsics (I
i have written a small piece of code. This code first blocks the {SIGSEGV},
Is there a simple script or piece of code I can add to my
I am new to jquery . I wrote small piece of code <div id=tablediv><table><tr><td><h2>Select

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.