0

I'm using posix_spawn function in 1 parent process to call other executable files child processes. I want to dedicate some of those child processes exclusively to a cpu for each (I know I cannot dedicate 4 of them as the kernel and other processes are critical and they should run, but let's assume now for at least 1 or 2 processes).

I ran htop command and I saw that all the 4 cores are being used, but I want to be able to have more control in case I got hundreds of processes so I decide which can run fully.

  • 1
    Do you really mean a single *CPU*, or a single CPU *core*? For a single *core* the term you should research is [*affinity*](https://en.wikipedia.org/wiki/Processor_affinity). However, you probably can't stop the OS from using the core for other processes and threads as well. – Some programmer dude Sep 05 '19 at 11:13
  • @Someprogrammerdude Yes I mean a single CPU core. Yes and I expect the OS will still use the core for other fundamental processes. –  Sep 05 '19 at 11:23
  • 1
    see this https://stackoverflow.com/a/54478296/7508077 – EsmaeelE Sep 05 '19 at 13:06

1 Answers1

1

You can use sched_setaffinity() system call to assign CPU core for a process. see manpage