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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:55:27+00:00 2026-06-02T03:55:27+00:00

I have a parent process which creates 2 server sockets and calls select() on

  • 0

I have a parent process which creates 2 server sockets and calls select() on them to wait for new connection. When the connection arrives, a message is sent to a child process (created with fork(), after servers sockets creation, so they are shared).

In this child, calling accept() on the server socket doesn’t work. I got a EAGAIN error (non-blocking socket). Whereas calling accept() in the main process works perfectly.

Of course, I don’t call accept() in the main process at all, I just tested to check if it worked, and it does.

Why can’t I call accept() in a child process after a select() in the parent?

EDIT: The goal here is to create a fixed number of workers (let’s say 8) to handle clients connections, as in the prefork model. These connections will be long-connections, not like HTTP. The goal is to load-balance connections between workers.

To do this, I use a shared memory variable which contains for a worker the number of currently connected clients. I want to “ask” the worker with the lowest number of clients to handle a new connection.

That’s why I do the select() in the parent, and then send a message to a child process, because I want to “choose” which process will handle the new connection.

The server listen on more than one sockets (one for ssl, one without), that’s why I use select() and not directly accept() in children processes, because I can’t accept() on multiple sockets in my children workers.

  • 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-02T03:55:29+00:00Added an answer on June 2, 2026 at 3:55 am

    In fact, the problem was not what I first thought. Here is a recap of what I did to have some basic load-balancing of connections between my worker processes.

    • A main process (the parent) creates 2 server sockets, bind() and listen() them (with and without ssl for example)
    • I create 8 children processes with a fork(), so they inherit the parent’s sockets
    • The main process runs select() in an infinite loop
    • When one of its two sockets is available, it sends a message to a child over a pipe. The child is determined thanks to a shared memory value, which contains the current number of clients “in the child process”. The process which currently handle the lowest number of clients is chosen.
    • This child process then calls accept() on the server socket (the socket to used between the two is passed in the pipe, so the child knows which one to call accept() on)

    The problem was that my parent process told a child to accept the socket and re-enter the loop immediately after, which it runs select() again. But if the child has not yet accepted the socket, select() returns again, for the same connection. That’s why I got a EAGAIN error, in fact I called accept() twice (or more depending on speed — inter process race conditions)!

    The solution is to wait for the child to answer something on the pipe like “Hey, I accepted the connection, it’s ok!”, and then returns to the select() loop.

    This works perfectly fine. The implementation in Python is available here for the curious : https://github.com/thibautd/Kiwi !

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

Sidebar

Related Questions

I am currently trying to communicate a parent process which should have multiple children
I have a parent thread (non-UI) which creates some child threads to do some
I have a parent thread (non-UI) which creates some child threads to do some
So I have a program which creates a child process and executes a command
I have a parent which when it starts, kicks off a thread that creates
I have a parent and a child process written in C language. Somewhere in
I have a parent class which contains a child object. I am using set
I have a long running process which monitors the system and prints periodic logs.
I have parent pom which configures certain plugins <pluginManagement> </plugins> <plugin> <artifactId>gmaven-plugin</artifactId> ... </plugin>
I have created a parent and a child process using fork( ), and both

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.