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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:32:55+00:00 2026-06-12T02:32:55+00:00

#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include structs.h #include server.h

  • 0
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

#include "structs.h"
#include "server.h"
#include "client.h"


int main(void)
{

  pid_t pid;
  int mypipe[2];
  int otherPipe[2];

  if(pipe(mypipe))
    {
      printf("Error in making a pipe");
    }
  if(pipe(otherPipe))
    {
      printf("Error creating another pipe");
    }
  if((pid=fork()) == -1)
    {
      perror("fork");
      exit(1);
    }
  printf("Child ID: %d" , pid);
  if(pid == 0)
    {
      close(mypipe[1]);
      close(otherPipe[0]);
      client *c = new client(mypipe[0], otherPipe[1]);
      wait(NULL);
      //c->startProgram();
      //return EXIT_SUCCESS;
    }
  else
    {
      printf("Yo");
    close(mypipe[0]);
    close(otherPipe[1]);
    server s;
    s.fdIn = otherPipe[0];
    s.fdOut = mypipe[1];
    s.startServer();
    //wait(NULL);
    //return EXIT_SUCCESS;
    }
}

Above is my code. The child process runs fine (If I remove that comment obviously), however the else never gets executed (Or am I missing something in the terminal?).

Here’s a screen shot of the output: https://i.stack.imgur.com/MawUJ.png

Any ideas on why it’s not going to the else/parent spot?

Thanks!

  • 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-12T02:32:56+00:00Added an answer on June 12, 2026 at 2:32 am

    Could it be because stdio is buffered? Try flushing output after printfing the child id. Or adding a \n. Or fprintfing it to stderr.

    EDIT: Just to clarify. My guess is not that it’s the reason it’s not getting to parent, for it is, it is why you do not see the output you expect.

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

Sidebar

Related Questions

Here is my code: #include<stdio.h> #include<stdlib.h> #include<sys/stat.h> #include<sys/types.h> #include<fcntl.h> #include<unistd.h> #include<errno.h> int main(int argc,char
This is my chat server : #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h>
#include<stdio.h> #include<unistd.h> #include<stdlib.h> #include<sys/ipc.h> #include<sys/msg.h> #include<sys/types.h> struct mbuffer{ long mtype; int mtext; }stResult; int
Have a look at the following code: #include<unistd.h> #include<stdlib.h> #include<stdio.h> #include<string.h> #include<sys/types.h> main() {
In this C program #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> int main()
#include <stdio.h> #include <stdlib.h> int main(void) { int x; int *in, *begin; in =
My test application is #include <sys/types.h> #include <sys/wait.h> #include <signal.h> #include <unistd.h> #include <stdio.h>
Here is my code for fork() system call, #include<stdio.h> #include<stdlib.h> #include<sys/types.h> #include<sys/stat.h> #include<unistd.h> #include<errno.h>
Given this code : #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/wait.h> #include <unistd.h>
When I try to use exec: #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <stdlib.h>

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.