How to save parent and child processes on one core

I understand that a process (parent) can be bound to core using sched_setaffinity , and then the forked process will inherit the affinity and will also be bound to the same core. However, I do not want to keep them tied to the same core forever. Ideally, I want them to stay together on the same CPU , that is, if the parent is ported by the OS scheduler, the child should follow the parent and be transferred to the same central processor as the parent.

One possible way is to have a shared variable where the parent periodically updates the current processor. Then the child can periodically look at this variable and sched_setaffinity to go to the same processor as the parent. However, this looks a bit hacky and may include periods when they run on separate processors. Any better ways to achieve this?

+6
source share
2 answers

Is it possible to run a child in a thread, and not in its own process?

+1
source

Did the Ganges help with planning? Then the parent and child will be jointly planned.

0
source

All Articles