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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:26:52+00:00 2026-05-26T14:26:52+00:00

What is the best way to do this theoretically? I need to let the

  • 0

What is the best way to do this theoretically? I need to let the user enter the number of processes to send to a pipe for instance “3” and as it loops through the three [three whats?] on each iteration I need to create a process, send it [what?] to the pipe and print it.

The next time the user enters another number, say “4”, it should print the previous 3 + 1.. I am working on this but can’t understand how do it. Here is my code. I just need guidance, no need to try to solve it for me (but suggestions would be much appreciated).

Right now I am able to send one through the pipe and return it but then the pipe closes and it does not allow for the other processes to get in there.

  • 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-26T14:26:53+00:00Added an answer on May 26, 2026 at 2:26 pm

    Suggestion #1: Use functions

    Use functions, even for little jobs such as:

    void create_fifo(const char *name)
    {
        /* Create the first named - pipe */
        int ret_val = mkfifo(name, 0666);
    
        if ((ret_val == -1) && (errno != EEXIST))
        {
            perror("Error creating the named pipe");
            exit(1);
        } 
    }
    

    Now you can simply write in your main program:

    create_fifo(PIPE1);
    create_fifo(PIPE5);
    

    This cuts down on the clutter in your main program. It also adheres to the Agile principle DRY – Don’t Repeat Yourself.

    Suggestion #2: Error check system calls.

    You did that for creating the FIFOs, which is good. You don’t for the open() calls, or the read() or write() calls. You probably should. I use a function similar to the following in my programs:

    #include <stdarg.h>
    #include <string.h>
    #include <stdio.h>
    #include <errno.h>
    
    static const char *arg0 = "did not call err_setarg0(argv[0])";
    
    void err_setarg0(const char *argv0)
    {
        arg0 = argv0;
    }
    
    void err_exit(const char *fmt, ...)
    {
        int errnum = errno;   /* Capture errno before it is changed */
        va_lists args;
        fprintf(stderr, "%s: ", arg0);
        va_start(args, fmt);
        vfprintf(stderr, fmt, args);
        va_end(args);
        if (errnum != 0)
            fprintf(stderr, "%d: %s\n", errnum, strerror(errnum));
        exit(1);
    }
    

    You can then use:

    if ((rdfd1 = open(PIPE1, O_RDONLY)) < 0)
        err_exit("Failed to open FIFO %s for reading: ", PIPE1);
    if ((wrfd1 = open(PIPE5, O_WRONLY)) < 0)
        err_exit("Failed to open FIFO %s for writing: ", PIPE5);
    

    Suggestion #3: Make an iterative server

    Your server program currently opens the FIFOs once, then reads from one, write to the other, and terminates. You need a loop around some portion of this code, maybe two nested loops. You have to decide whether you need an inner loop to read until EOF. You also need to know how you will terminate the server.

    Suggestion #4: Maybe the server needs pipe names as arguments

    Your server currently works on fixed FIFO names. You probably need it to take input and output file names as command line arguments, so that when your client spawns multiple servers, each server can have its own set of FIFOs, rather than all processes sharing the same two FIFOs, which is going to lead to confusion and chaos.

    Indeed, the need for generating names calls the whole design into question – are you sure using FIFOs is the best way to do this? It looks to me like a case where anonymous pipes would serve you better; you wouldn’t have to invent names, and the server would simply read from its standard input and write the (modified?) data to its standard output, so you could even simply use cat or tr or sed or … as your server.

    Clearly, if you use pipes, you will need to do some careful plumbing, but you also need to do careful plumbing with the pairs of FIFOs per server.

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

Sidebar

Related Questions

what's the best way to accomplish this task? (new to sharepoint) Do we need
The best way of describing this is I have a table of people with
Is the best way to do this with Regex? I don't want it picking
What is the best way to solve this? A static member is one for
What is the best way to solve this problem in code? The problem is
What's the best way to abstract this pattern: class MyClass attr_accessor :foo, :bar def
what is the best way to do this?
Any suggestions on the best way to display this table on an Android platform?
What is the best way of doing this in Python? for (v = n
What's the best way to do this with Linq? I have a List 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.