Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent inheriting CPU affinity by child forked process?

I have a server process that forks many child processes. The server process has affinity to a CPU core, but I don't want that affinity to be inherited by child process (rather OS should handle where to run these processes). Is there a way to delink parent child processes with respect to cpu affinity?

like image 880
user424060 Avatar asked Dec 01 '11 03:12

user424060


People also ask

When a process is forked the child process inherits?

* The child inherits copies of the parent's set of open file descriptors. Each file descriptor in the child refers to the same open file description (see open(2)) as the corresponding file descriptor in the parent.

Is CPU affinity inherited?

That's why the processor affinity mask is inherited: If you set it on the parent process, this covers all the child helper processes that process may launch as part of its execution. Another reason why you might want to set a process's affinity mask is to restrict its CPU usage.

Which properties child process do not inherit from parent process?

The child's parent process ID is the same as the parent's process ID. The child does not inherit its parent's memory locks and semaphore adjustments.

How does forking affect the parent process?

fork() creates a new process by duplicating the calling process. The new process is referred to as the child process. The calling process is referred to as the parent process. The child process and the parent process run in separate memory spaces.


1 Answers

You can call sched_setaffinity(2) with all bits set in CPU mask after the fork(2) and before the execve(2).

like image 72
Nikolai Fetissov Avatar answered Sep 28 '22 06:09

Nikolai Fetissov