Solved

enumerating processes with CreateToolhelp32Snapshot

Posted on 2006-07-11
6
1,012 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

691 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