Solved

enumerating processes with CreateToolhelp32Snapshot

Posted on 2006-07-11
6
994 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Would like to move button in a function 3 73
Writing a parser for java language 4 71
Why isn't object file created? 6 43
Installshield for Embarcadero EX 10.1 Berlin 4 21
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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

863 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

22 Experts available now in Live!

Get 1:1 Help Now