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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:11:36+00:00 2026-05-30T12:11:36+00:00

I have a socket server in C/linux. Each time I create a new socket

  • 0

I have a socket server in C/linux. Each time I create a new socket it is assigned a file descriptor. I want to use these FD’s as uniqueID’s for each client. If they are guaranteed to always be assigned in increasing order (which is the case for the Ubuntu that I am running) then I could just use them as array indices.

So the question: Are the file descriptors that are assigned from linux sockets guaranteed to always be in increasing order?

  • 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-30T12:11:38+00:00Added an answer on May 30, 2026 at 12:11 pm

    FD’s are guaranteed to be unique, for the lifetime of the socket. So yes, in theory, you could probably use the FD as an index into an array of clients. However, I’d caution against this for at least a couple of reasons:

    • As has already been said, there is no guarantee that FDs will be allocated monotonically. accept() would be within its rights to return a highly-numbered FD, which would then make your array inefficient. So short answer to your question: no, they are not guaranteed to be monotonic.

    • Your server is likely to end up with lots of other open FDs – stdin, stdout and stderr to name but three – so again, your array is wasting space.

    I’d recommend some other way of mapping from FDs to clients. Indeed, unless you’re going to be dealing with thousands of clients, searching through a list of clients should be fine – it’s not really an operation that you should need to do a huge amount.

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

Sidebar

Related Questions

I have to create an sample code that connect to a socket server, and
We create a socket. On one side of the socket we have a server
I have a class that encapsulates tcp socket communications with a server. For each
I have a server in linux using the Berkeley_sockets and I create a TCP
I am doing coding in linux architecture. I have question regarding socket server and
I have a server that sends data via a socket, the data is a
I have a server that listens for a connection on a socket: public class
Hey all. I have a server written in java using the ServerSocket and Socket
Hey gang. I have just written a client and server in C++ using sys/socket.
I have a socket application which I can use in local network, at home.

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.