1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Set affinity of already running task(s)

Discussion in 'Win32' started by PhreakShow, Sep 8, 2010.

  1. PhreakShow

    PhreakShow New Member

    Sep 8, 2010
    Likes Received:
    Trophy Points:
    Hi folks,
    I've been silently reading (and searching) this forum for quite a while, but now I need to open a new thread because I didn't find a solution.

    The problem is: I have to create a program which is given the PID of a runing task, and then display the affinity mask. I wrote a sample containing this code:

    DWORD dwProcessAffinityMask, dwSystemAffinityMask;
    GetProcessAffinityMask( hProcess, &dwProcessAffinityMask, &dwSystemAffinityMask );

    This gives me a "3", which is correct because I'm running it at a Core2Duo machine. I also tested it on a 4x Double-Xeon machine with 128 logical CPUs, on which it returns "2^32 -1".
    But I'm stuck at this point, the last output doesn't make any sense.

    A huge problem is, that I cannot pass just the PID to GetProcessAffinityMask(), but the handle.
    How do I "convert" a PID to the correct handle or a already running task?

Share This Page