bhh
bhh

Reputation: 1

Is there a way to set mempolicy by pid on running precess?

I know that there aren't parameter 'pid' at set_mempolicy() so, I couldn't set mempolicy by pid on running process. (like numactl interleave, membind, etc)

Is there any way to set mempolicy by pid on running process?

I tried to confirm numactl mempolicy code and setting conditions but I couldn' get answer.

Upvotes: 0

Views: 110

Answers (1)

Muslimbek Abduganiev
Muslimbek Abduganiev

Reputation: 941

I am not sure if it works, but you could try to attach the external process to yours using ptrace() and then use set_mempolicy.

Something like this:

  1. Attach to the target process using ptrace(PTRACE_ATTACH, pid, 0, 0).
  2. Wait for the target process to stop.
  3. Get the current memory policy of the target process using get_mempolicy() or similar methods.
  4. Modify the memory policy as needed.
  5. Set the new memory policy using set_mempolicy() or similar methods.
  6. Detach from the target process using ptrace(PTRACE_DETACH, pid, 0, 0).

Upvotes: 0

Related Questions