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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:00:15+00:00 2026-06-14T17:00:15+00:00

I am forking multiple processes from a manager process. I then would like to

  • 0

I am forking multiple processes from a manager process. I then would like to make a random port number for these forked processes to listen on. However, when I seed random, and get a random number, I get the same number between the three processes. For example:

manager:

int main(){
 for(int i = 0; i < rCount; i++){
  pid_t pid = fork();
  if (pid == 0) {// child
        execl(ROUTERLOCATION,"",NULL); //create router process
   }
   else { // parent
    }
  }
}

router:

int main(){
  randomPort(); 
}
void randomPort(){
    srand(time(NULL));
    int host_port = rand() % 99999 + 11111;
    cout << houst_port << endl;
}

I have tried seeding at the manager, and then trying rand at the process, but I still have the same problem of getting the same number when I can rand. Can I seed with anything besides the time, and still get good random results.

  • 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-14T17:00:16+00:00Added an answer on June 14, 2026 at 5:00 pm

    Since the time will be the same for every process, you need another input that is guaranteed to be different between the processes. The process number works well for this. Combine the two by adding the process number to the time.

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

Sidebar

Related Questions

In MediaWiki, we would like to display tables of contents (from multiple pages) on
I am now trying to do forking in php. I would like to do
I am writing a program that uses multiple worker processes (a pre-forking model) with
Say a process is forked from another process. In other words, we replicate a
does PHP support something like ampersand in bash (forking)? Let's say I wanted to
To implement a timer, I'm currently forking a process that uses SIGALRM to periodically
I have a section of code that I need to remove from multiple files
I'm trying to insert multiple rows using SqlCommand from C# to SQL Server. I'm
I'm creating a multiple column list using the directions from this article: http://csswizardry.com/2010/02/mutiple-column-lists-using-one-ul/ In
So I'm implementing a svg-editor-like GUI on one application I'm working here. These are

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.