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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:52:00+00:00 2026-06-11T16:52:00+00:00

Running on Ubuntu. Program is in C++. I have 2 process running on different

  • 0

Running on Ubuntu. Program is in C++.
I have 2 process running on different hosts , when one is master and one is slave (don’t have any priority between them, just that only one handle request.).
Only one process can be a master and handle request.
Two process always up and in case they are crash there is a watch dog that restart them.

The hosts are connected by network cable.

My plan is to ask for keep alive from one to other and in case that slave stop getting keep alive from master it need to change its state to master.
When master start up again it first wait to get keep alive and in case not get it set role as master. if get it set role as slave.

I will be happy to get your opinion on:

how to prevent from both to be master at the same time? This is my MAJOR concern. When start up and in connectvity failure, how do you prevent 2 master at the same time?

Do you think that it will be better to query for keep alive or to send keep alive? ( for my opinion its better to ask for keep alive than push )

any other good advices and pitfalls will be more than welcome.

  • 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-11T16:52:01+00:00Added an answer on June 11, 2026 at 4:52 pm

    The way I’ve done this is to have each process spawn a heartbeat thread that sends out a UDP packet once a second, and listens for incoming UDP packets from the other process. If the heartbeat thread doesn’t receive any UDP packets from the other process for a specified amount of time (e.g. 5 seconds), it assumes the other process is down and notifies the parent thread that it should be come the master now.

    The reason the heartbeat sending/listening is done in a dedicated thread is because that way if the main thread is busy doing a lengthy calculation, it won’t cause heartbeat UDP packets to temporarily not be sent. That way the algorithms in the main thread don’t need to be real-time in order to avoid triggering spurious failovers.

    There is another issue to think about here… what happens if a network problem temporarily cuts communication between the two hosts? (e.g. some joker or QA tester unplugs the Ethernet cable for 1 minute, then plugs it back in) In that case, both processes will stop receiving UDP packets from the other process, so both processes will think the other process has gone away, and both will become the master process. Then when the network cable is reconnected, you have two master processes running at once, which is not what you want. So you need some way for two master processes to decide which of the two should demote itself back to slave status, to satisfy the Highlander Principle (“there can be only one!”). This could be as simple as “the host with the smallest IP address should remain master”, or you could have each heartbeat packet contain the sending process’s uptime, and the host with the larger uptime should remain master, or etc.

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

Sidebar

Related Questions

I have a program in C++, using the standard socket API, running on Ubuntu
I have a GTK program running on Ubuntu 10.04 that hangs in interruptible state,
Running the following program on gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 and Intel(R) Core(TM)2 Duo CPU,
I am running Ubuntu 9.04 and have done about a half hour worth of
I got a long running program that I don't want to kill, but I
I am running Linux Ubuntu 10.04 and I have a Windows 7 machine and
I'm writing a cgi-bin program for my Sheevaplug (running the default Ubuntu install) that
Need some advice, I'm after a decent process/task manager for Ubuntu. Basically I have
I have a dual socket Xeon E5522 2.26GHZ machine (with hyperthreading disabled) running ubuntu
I have SBCL running on a Ubuntu machine. I want to write a little

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.