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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:24:51+00:00 2026-05-13T20:24:51+00:00

For my application, I need to have a central process responsible for interacting with

  • 0

For my application, I need to have a central process responsible for interacting with many client processes. The client processes need a way to identify and communicate with the central process. Additionally, the central process may not be running, and the client process needs a way to identify that fact. This application will be running on a Unix-like system, so I’d thought about using named pipes sockets for the task. How would I, specifically, go about using named pipes sockets for this task (actual code would be greatly appreciated!)? If named pipes sockets are not ideal, are there better alternatives?

  • 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-13T20:24:52+00:00Added an answer on May 13, 2026 at 8:24 pm

    Named pipes are not really ideal for this – they are best suited for single-reader, single-writer situations.

    UNIX-domain sockets, however, are perfectly suited for it. They use the sockets API, with the endpoint name being a filesystem entry (as with a named pipe).


    Here’s a very simple example (you will of course want to add copious error checking!). First the server side:

    #include <stdio.h>
    #include <sys/socket.h>
    #include <sys/un.h>
    #include <unistd.h>
    
    #define SOCKNAME "/tmp/foo"
    
    int main()
    {
        int s1, s2;
        int i;
        struct sockaddr_un sa = { AF_UNIX, SOCKNAME };
    
        unlink(SOCKNAME);
        s1 = socket(AF_UNIX, SOCK_STREAM, 0);
        bind(s1, (struct sockaddr *)&sa, sizeof sa);
        listen(s1, 5);
    
        for (i = 0; i < 10; i++)
        {
            struct sockaddr_un sa_client;
            socklen_t sa_len = sizeof sa_client;
            FILE *f;
    
            s2 = accept(s1, (struct sockaddr *)&sa_client, &sa_len);
            f = fdopen(s2, "r+");
            fprintf(f, "Hello, you are client number %d\n", i + 1);
            fclose(f);
        }
    
        return 0;
    }
    

    Now the client side:

    #include <stdio.h>
    #include <sys/socket.h>
    #include <sys/un.h>
    
    #define SOCKNAME "/tmp/foo"
    
    int main()
    {
        int s1;
        struct sockaddr_un sa = { AF_UNIX, SOCKNAME };
        FILE *f;
        char buffer[1024];
    
        s1 = socket(AF_UNIX, SOCK_STREAM, 0);
        connect(s1, (struct sockaddr *)&sa, sizeof sa);
        f = fdopen(s1, "r+");
    
        while (fgets(buffer, sizeof buffer, f) != NULL)
        {
            printf("Message received: %s", buffer);
        }
    
        fclose(f);
    
        return 0;
    }
    

    Note that you should actually create the socket under /var/run/yourappname rather than in /tmp.

    man 7 unix is a good resource for further investigation.

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

Sidebar

Ask A Question

Stats

  • Questions 312k
  • Answers 312k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The default engine can be specified at the server level,… May 13, 2026 at 10:33 pm
  • Editorial Team
    Editorial Team added an answer I think that what SecurityAction.Demand does is throw a security… May 13, 2026 at 10:33 pm
  • Editorial Team
    Editorial Team added an answer Take a look at XmlDocument.ImportNode. May 13, 2026 at 10:33 pm

Related Questions

I need to process large image files into smaller image files. I would like
I am wondering what's the best way to insert customization hooks into my application.
I have a requirement where I need to be able to access a list
I have an application that is made up of the following: A central database
My application has several workers (working on different things as different processes) and some

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.