Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix potential bug in building process tree on Win #5153

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/procinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ void find_children(PROC_MAP& pm) {
int parentid = i->second.parentid;
PROC_MAP::iterator j = pm.find(parentid);
if (j == pm.end()) continue; // should never happen
#ifdef _WIN32
// In Windows:
// 1) PIDs are reused, possibly quickly
// 2) if a process creates children and then exits,
// the parentID of the children are not cleared,
// so they may soon refer to an unrelated process.
// (this is horrible design, BTW)
// This can cause problems:
// - when we abort a BOINC app we kill the process and its descendants
// (based on parent ID). These could be unrelated processes.
// - If a BOINC app gets a process ID that is the parentID of
// orphan processes, its CPU time will be computed incorrectly.
// To fix this, don't create a parent/child link
// if the parent was created after the child.
//
if (j->second.create_time.QuadPart > i->second.create_time.QuadPart) {
continue;
}
#endif
j->second.children.push_back(i->first);
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/procinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ struct PROCINFO {
// running at or below priority of BOINC apps
char command[256];
bool scanned;

double page_fault_rate; // derived by higher-level code
std::vector<int> children;
#ifdef _WIN32
LARGE_INTEGER create_time;
#endif

PROCINFO() {
clear();
Expand Down
1 change: 1 addition & 0 deletions lib/procinfo_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ int get_procinfo_XP(PROC_MAP& pm) {
p.user_time = ((double) pProcesses->UserTime.QuadPart)/1e7;
p.kernel_time = ((double) pProcesses->KernelTime.QuadPart)/1e7;
p.is_low_priority = (pProcesses->BasePriority <= 4);
p.create_time = pProcesses->CreateTime;
WideCharToMultiByte(CP_ACP, 0,
pProcesses->ProcessName.Buffer,
pProcesses->ProcessName.Length,
Expand Down