This works on windows:
void winTerminateChildProcesses()
{
HANDLE hProcessSnap;
PROCESSENTRY32 pe32;
// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( hProcessSnap == INVALID_HANDLE_VALUE )
{
qDebug() << "Error: CreateToolhelp32Snapshot";
return;
}
// Set the size of the structure before using it.
pe32.dwSize = sizeof( PROCESSENTRY32 );
// Retrieve information about the first process,
// and exit if unsuccessful
if( !Process32First( hProcessSnap, &pe32 ) )
{
qDebug() << "Error: Process32First";
CloseHandle( hProcessSnap ); // clean the snapshot object
return;
}
ProcTree procTree;
// Now walk the snapshot of processes, and
// display information about each process in turn
do
{
procTree[pe32.th32ParentProcessID] << pe32.th32ProcessID;
}
while( Process32Next( hProcessSnap, &pe32 ) );
CloseHandle( hProcessSnap );
QHashIterator<DWORD, QSet<DWORD>> i(procTree);
while (i.hasNext()) {
i.next();
qDebug() << i.key() << ": " << i.value() << endl;
}
}
void winTerminateChildProcesses()
{
HANDLE hProcessSnap;
PROCESSENTRY32 pe32;
// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( hProcessSnap == INVALID_HANDLE_VALUE )
{
qDebug() << "Error: CreateToolhelp32Snapshot";
return;
}
// Set the size of the structure before using it.
pe32.dwSize = sizeof( PROCESSENTRY32 );
// Retrieve information about the first process,
// and exit if unsuccessful
if( !Process32First( hProcessSnap, &pe32 ) )
{
qDebug() << "Error: Process32First";
CloseHandle( hProcessSnap ); // clean the snapshot object
return;
}
ProcTree procTree;
// Now walk the snapshot of processes, and
// display information about each process in turn
do
{
procTree[pe32.th32ParentProcessID] << pe32.th32ProcessID;
}
while( Process32Next( hProcessSnap, &pe32 ) );
CloseHandle( hProcessSnap );
QHashIterator<DWORD, QSet<DWORD>> i(procTree);
while (i.hasNext()) {
i.next();
qDebug() << i.key() << ": " << i.value() << endl;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks