• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1344
  • Last Modified:

How to set Processor Affinity

Anyone know how in coding to force a VC6 C++ application to use just one processor?
0
_kp
Asked:
_kp
  • 4
  • 4
1 Solution
 
bkrahmerCommented:
Just use SetProcessAffinityMask, passing in a handle to your process, and a bitmask identifying a single, valid, processor.
0
 
_kpAuthor Commented:
Thanks, I saw that in the help files as well, but the Get/SetProcessAffinityMask isn't working for some reason. I was looking for the code to actually set it, to see why it isn't working.
0
 
bkrahmerCommented:
Are you getting an error code?  What does your code look like?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
_kpAuthor Commented:
no valid answers submitted, question withdrawn, request refund.
0
 
SpideyModCommented:
A request for a refund has been made.  Experts you have 72 hours to object.

SpideyMod
Community Support Moderator @Experts Exchange
0
 
bkrahmerCommented:
Yes, I object.  I gave the right answer.  I have used it, and it works just fine.

brian
0
 
_kpAuthor Commented:
I was asking HOW to do it. You gave me the same thing I already read in the help files.
0
 
bkrahmerCommented:
kp, you are treating me pretty badly here.  You claim that you knew about SetProcessAffinityMask, but you never mentioned that in your post.  You said the code still didn't work, so I asked you for the code, and you ignored me.  
Here is some code.  It works great on my SMP box.  There's nothing exotic in there, common sense straight out of the docs.

   HANDLE myProc = GetCurrentProcess();
   DWORD procAffinity, sytemAffinity;

   if (GetProcessAffinityMask(myProc, &procAffinity, &sytemAffinity))
   {
      printf("(1) Process Affinity: %x, System Affinity: %x\n", procAffinity, sytemAffinity);
   }
   else
   {
      printf("GetProcessAffinityMask (call 1) failed.\n");
   }

   if (sytemAffinity > 1)
   {
      procAffinity ^= 1;
      if (SetProcessAffinityMask(myProc, procAffinity))
      {
         if (GetProcessAffinityMask(myProc, &procAffinity, &sytemAffinity))
         {
            printf("(2) Process Affinity: %x, System Affinity: %x\n", procAffinity, sytemAffinity);
         }
         else
         {
            printf("GetProcessAffinityMask (call 2) failed.\n");
         }
      }
      else
      {
         printf("SetProcessAffinityMask failed.\n");
      }
   }


brian
0
 
_kpAuthor Commented:
Read my 2nd.  post. I had asked for the code as it wasn't working for me. There was no intent to treat you badly in any way. You simply weren't answering the question I had asked. Thanks for the code.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now