Solved

enumerating processes with CreateToolhelp32Snapshot

Posted on 2006-07-11
6
1,001 Views
Last Modified: 2010-08-05
Hello C++ experts,

I am a VB programmer mostly and I have code that enumerates the currently running processes of the PC using CreateToolhelp32Snapshot... but it has recently come to my attention that every time CreateToolhelp32Snapshot is called, it significantly increases the 'Page Fault' count in my Task Manager.  Now I see all my other programs that are running also have some of these 'Page Faults' too, but the app I wrote calls CreateToolhelp32Snapshot in a loop and so these 'Page Faults' add up very quickly to super high numbers.

Now I have researched a bit and I don't think there is anything too alarming about this, but some people who have used my program have criticized it for having this huge number of Page Faults...

So what I am trying to figure out is if this has anything to do with VB or if the CreateToolhelp32Snapshot will increase Page Faults in a C++ app too.  I have narrowed it down to that exact call of CreateToolhelp32Snapshot, and once the snapshot is open there is no problem calling the other enumeration APIs (such as Process32First etc).  And YES I am also calling CloseHandle on the snapshot after using it.

Can someone please try creating a simple C++ app that calls CreateToolhelp32Snapshot and check in your Task Manager to see if the Page Faults increase each time it's called (NOTE: the Page Faults tab is not visible by default, you have to go to the 'Processes' tab and then VIEW > SELECT COLUMNS... to add the Page Faults column).

If someone can run this quick test for me I would really appreciate it and it will help me know how to proceed if this is fixable.  : )
0
Comment
Question by:RobK6364
[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
  • 3
  • 2
6 Comments
 
LVL 12

Assisted Solution

by:rajeev_devin
rajeev_devin earned 25 total points
ID: 17088135
0
 
LVL 17

Accepted Solution

by:
rstaveley earned 75 total points
ID: 17089585
Running http://msdn.microsoft.com/library/en-us/perfmon/base/taking_a_snapshot_and_viewing_processes.asp with the modification...

 void main( )
{
  while (1) {
    Sleep(500);
    GetProcessList( );
  }
}

...causes lost of page faults. I therefore don't think it is a Visual Basic problem.
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 17089590
s/lost/lots/
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!

 
LVL 1

Author Comment

by:RobK6364
ID: 17092734
Thanks rstaveley, I guess it's not a VB problem... at least now I know.

I think the link rajeev pointed to...
http://www.osronline.com/showThread.cfm?link=70639
... seems to possibly describe the problem and why CreateToolhelp32Snapshot increases the Page Faults (due to creating threads in the other processes), but at the end he says he managed to fix this by using the System process.  I guess I'm not really sure what he (Ladik) means when he describes his solution... anyone have any suggests?

Or if anyone knows any other way to enumerate the currently running processes?
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 17093910
Have you tried .NET for comparison? e.g. http://www.freevbcode.com/ShowCode.asp?ID=2535
0
 
LVL 1

Author Comment

by:RobK6364
ID: 17094828
I found another function, EnumProcesses, that works only on NT machines but that suits my purposes.  When EnumProcesses is used, there is no Page Fault problem. : )
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

735 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