?
Solved

How to set Processor Affinity

Posted on 2003-02-25
9
Medium Priority
?
1,343 Views
Last Modified: 2009-01-22
Anyone know how in coding to force a VC6 C++ application to use just one processor?
0
Comment
Question by:_kp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 2

Expert Comment

by:bkrahmer
ID: 8023394
Just use SetProcessAffinityMask, passing in a handle to your process, and a bitmask identifying a single, valid, processor.
0
 

Author Comment

by:_kp
ID: 8024778
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
 
LVL 2

Expert Comment

by:bkrahmer
ID: 8026606
Are you getting an error code?  What does your code look like?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:_kp
ID: 8272196
no valid answers submitted, question withdrawn, request refund.
0
 

Expert Comment

by:SpideyMod
ID: 8272246
A request for a refund has been made.  Experts you have 72 hours to object.

SpideyMod
Community Support Moderator @Experts Exchange
0
 
LVL 2

Expert Comment

by:bkrahmer
ID: 8273834
Yes, I object.  I gave the right answer.  I have used it, and it works just fine.

brian
0
 

Author Comment

by:_kp
ID: 8273857
I was asking HOW to do it. You gave me the same thing I already read in the help files.
0
 
LVL 2

Accepted Solution

by:
bkrahmer earned 75 total points
ID: 8274143
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
 

Author Comment

by:_kp
ID: 8275074
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question