Results 1 to 7 of 7

Thread: Find child processes

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Aug 2010
    Posts
    36
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Find child processes

    This works on windows:


    Qt Code:
    1. void winTerminateChildProcesses()
    2. {
    3. HANDLE hProcessSnap;
    4. PROCESSENTRY32 pe32;
    5.  
    6. // Take a snapshot of all processes in the system.
    7. hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
    8. if( hProcessSnap == INVALID_HANDLE_VALUE )
    9. {
    10. qDebug() << "Error: CreateToolhelp32Snapshot";
    11. return;
    12. }
    13.  
    14. // Set the size of the structure before using it.
    15. pe32.dwSize = sizeof( PROCESSENTRY32 );
    16.  
    17. // Retrieve information about the first process,
    18. // and exit if unsuccessful
    19. if( !Process32First( hProcessSnap, &pe32 ) )
    20. {
    21. qDebug() << "Error: Process32First";
    22. CloseHandle( hProcessSnap ); // clean the snapshot object
    23. return;
    24. }
    25.  
    26. ProcTree procTree;
    27.  
    28. // Now walk the snapshot of processes, and
    29. // display information about each process in turn
    30. do
    31. {
    32. procTree[pe32.th32ParentProcessID] << pe32.th32ProcessID;
    33. }
    34. while( Process32Next( hProcessSnap, &pe32 ) );
    35.  
    36. CloseHandle( hProcessSnap );
    37.  
    38. QHashIterator<DWORD, QSet<DWORD>> i(procTree);
    39. while (i.hasNext()) {
    40. i.next();
    41. qDebug() << i.key() << ": " << i.value() << endl;
    42. }
    43.  
    44. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 24th May 2011 at 08:42. Reason: code tags

Similar Threads

  1. Replies: 0
    Last Post: 22nd February 2011, 07:55
  2. Find non child dialog
    By moh.gup@gmail.com in forum Qt Programming
    Replies: 6
    Last Post: 5th April 2010, 06:48
  3. Replies: 1
    Last Post: 6th March 2007, 15:27
  4. how to find a child widget?
    By TheRonin in forum Qt Programming
    Replies: 1
    Last Post: 8th November 2006, 10:30
  5. Enumerate processes using Qt
    By Ben.Hines in forum Qt Programming
    Replies: 5
    Last Post: 14th February 2006, 15:45

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.