Solved

enumerating processes with CreateToolhelp32Snapshot

Posted on 2006-07-11
6
992 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now