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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:39:32+00:00 2026-05-26T11:39:32+00:00

I am trying to make this work but no luck, basically i need to

  • 0

I am trying to make this work but no luck, basically i need to write to the pipe and then make the pipe return back with the text i sent. I have a server.c and client.c , so i make the server.c run…, open a new terminal and then run the client.. the problem is that the client doesnt do anything when i run it.. I am sure i am missing something.. like closing the pipe. i am not sure.. I would really appreciate some guidance

server.c

#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#define PIPE1      "PIPE1"
#define PIPE5      "PIPE5"

#define MAX_BUF_SIZE    255

int main(int argc, char *argv[])
{
    int rdfd1,rdfd2,rdfd3,rdfd4, wrfd1,wrfd2,wrfd3,wrfd4,ret_val, count, numread1,numread2,numread3,numread4;
    char buf1[MAX_BUF_SIZE];
    char buf2[MAX_BUF_SIZE];
    char buf3[MAX_BUF_SIZE];
    char buf4[MAX_BUF_SIZE];

    /* Create the first named - pipe */
    ret_val = mkfifo(PIPE1, 0666);


    if ((ret_val == -1) && (errno != EEXIST)) {
        perror("Error creating the named pipe");
          return 1; 
    }



    ret_val = mkfifo(PIPE5, 0666);

    if ((ret_val == -1) && (errno != EEXIST)) {
        perror("Error creating the named pipe");
        return 1; 
    }

    /* Open the first named pipe for reading */
    rdfd1 = open(PIPE1, O_RDONLY);


    /* Open the first named pipe for writing */
    wrfd1 = open(PIPE5, O_WRONLY);


    /* Read from the pipes */
    numread1 = read(rdfd1, buf1, MAX_BUF_SIZE);


    buf1[numread1] = '0';

    printf("Server : Read From the  pipe : %sn", buf1);


    /* 
     * Write the converted content to 
     * pipe 
     */    
   write(wrfd1, buf1, strlen(buf1));

}

client.c

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define PIPE1      "PIPE1"
#define PIPE5      "PIPE5"


#define MAX_BUF_SIZE    255


int main(int argc,  char *argv[ ]) {
   pid_t childpid;             
   int error;                  
   int i;                     
   int nprocs;                
           /* check command line for a valid number of processes to generate */

   int wrfd1, rdfd1, numread;
    char rdbuf[MAX_BUF_SIZE];

   if ( (argc != 2) || ((nprocs = atoi (argv[1])) <= 0) ) {
       fprintf (stderr, "Usage: %s nprocs\n", argv[0]);
       return 1; 
   }  



   for (i = 1; i < nprocs;  i++) {  
       /* create the remaining processes */

            if ((childpid = fork()) == -1) {
                  fprintf(stderr, "[%ld]:failed to create child %d: %s\n", (long)getpid(), i, strerror(errno));
                   return 1; 
                } 

          /* Open the first named pipe for writing */
          wrfd1 = open(PIPE5, O_WRONLY);

          /* Open the second named pipe for reading */
         rdfd1 = open(PIPE1, O_RDONLY);


         if (childpid)
         break;

           char string1[100];

            if(sprintf(string1, "This is process %d with ID %ld and parent id %ld\n", i,  (long)getpid(), (long)getppid())) {
              write(wrfd1,string1, strlen(string1));
              }

         /* Read from the pipe */
         numread = read(rdfd1, rdbuf, MAX_BUF_SIZE);

         rdbuf[numread] = '0';

         printf("Full Duplex Client : Read From the Pipe : %sn", rdbuf);    
      } 


   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-26T11:39:32+00:00Added an answer on May 26, 2026 at 11:39 am

    It seems like both server and client read from PIPE1 and write to PIPE5. Shouldn’t one of them write to PIPE1 so that the other can read it from the other end?

    Also, if you’re testing with ./client 1, your for (i = 1; i < nprocs; i++) loop will never execute.

    One last thing, see this question. I’m not entirely sure it applies to your code, but it’s worth keeping in mind.

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

Sidebar

Related Questions

I've been trying to make this work for some time now, but I think
I am trying to make this work but have been unlucky it is giving
I'm trying to make this fragment work: Version History --------------- These are the versions
im trying to make Categories and Subcategories, im checking this models but i have
I'm trying to make this work (in GCC 4.6) without barking at me. #define
I'm trying to make this jquery plugin => http://leandrovieira.com/projects/jquery/lightbox/ work with multiple galleries on
Yes, sound weird. But I'm trying to make a text editor inside the browser.
I'm trying to make a subclass of NSCalendar, but without much luck. I've tried
I am trying to make this landscape only iphone app. I only use this
I have been trying to make this to be a little jQuery plugin that

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.