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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:53:55+00:00 2026-06-01T06:53:55+00:00

On a multi-core machine, why doesn’t the CPU automatically move a process to a

  • 0

On a multi-core machine, why doesn’t the CPU automatically move a process to a new core if there are multiple processes all on the same core at full capacity?

Here is a sample program which reproduces the problem I’m seeing:

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

void RunClient(int i) {
  printf("Starting client %d\n", i);
  while (true) {
  }
}


int main(int argc, char** argv) {
  for (int i = 0; i < 4; ++i) {
    pid_t p_id = fork();
    sleep(3);
    if (p_id == -1) {
      perror("fork");
    } else if (p_id == 0) {
      RunClient(i);
      exit(0);
    }
  }

  return 0;
}

This works as expected (when I check top, I see all 4 processes are running at 100%).

However, if I remove the “sleep(3)” line, then sometimes multiple processes are set to the same CPU and thus not running at full capacity (for example, one process might be at 100% while the other 3 are each at 33%). What’s going on and how do I fix it?

I know I can manually set the CPU affinity, but that seems like a fragile solution?

  • 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-01T06:53:56+00:00Added an answer on June 1, 2026 at 6:53 am

    This isn’t an issue with your code, it’s an issue with your OS scheduler. It works as expected for me (ubuntu 11.10) both with and without the sleep(3)

    But +1 for posting an SSCCE

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

Sidebar

Related Questions

I use mpi4py and openmpi on a multi-cpu/core machine to do linear algebra. My
Does the threads of a single process run in parallel on a multi-core machine
What advantages are there to programming for a non-cache-coherent multi-core machine? Cache_coherence has many
How does COM ensure that on a multi-core machine, it stays in Sync if
Possible Duplicate: Would a multithreaded Java application exploit a multi-core machine very well? I
Could anyone explain to me the differences between multi-CPU, multi-core, and hyper-thread? I am
I'm running a C# Console Application that is multi-threaded. The core process retrieves some
As multi-processor and multi-core computers become more and more ubiquitous, is simply firing off
Follow up question from Multi-core usage, threads, thread-pools . Are threads moved from one
I see a lot of the multi-core information on the web applied to desktop

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.