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
Solved

enumerating processes with CreateToolhelp32Snapshot

Posted on 2006-07-11
6
997 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
MSVCR80.dll crash 2 141
getting a fire fox page (view page source ) in c++ 6 42
Compile GLUT with Visual Studio 2015 1 174
Unable to start eclipse ? 17 154
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

829 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