How to keep parent and child process on same core

view full story

http://stackoverflow.com – I understand that a process (parent) can be pinned to a core using sched_setaffinity and then the forked process inherits the affinity and would also be pinned on the same core. However, I don't want to keep them pinned together to the same core forever. Ideally, what I want is for them to stay together on the same CPU i.e. if parent is migrated by the OS scheduler, the child should follow the parent and get migrated to the same CPU as parent. One possible way is to have a shared variable where parent updates its current CPU periodically. Then the child can look up this variable periodically (HowTos)