本文整理汇总了C++中ProcessInfo::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ ProcessInfo::clear方法的具体用法?C++ ProcessInfo::clear怎么用?C++ ProcessInfo::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProcessInfo
的用法示例。
在下文中一共展示了ProcessInfo::clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadProcessInfo
bool ProcFS::ReadProcessInfo(pid_t pid, ProcessInfo &info) {
pid_t ppid;
uid_t uid, euid;
gid_t gid, egid;
ELFInfo elf;
std::string path;
info.clear();
if (!ReadProcessIds(pid, ppid, uid, euid, gid, egid) ||
!GetProcessELFInfo(pid, elf) ||
(path = GetProcessExecutablePath(pid)).empty())
return false;
info.pid = pid;
info.parentPid = ppid;
info.name.swap(path);
info.realUid = uid;
info.effectiveUid = euid;
info.realGid = gid;
info.effectiveGid = egid;
if (!ELFSupport::MachineTypeToCPUType(elf.machine, elf.is64Bit, info.cpuType,
info.cpuSubType)) {
info.cpuType = kCPUTypeAny;
info.cpuSubType = kCPUSubTypeInvalid;
}
info.nativeCPUType = elf.machine;
info.nativeCPUSubType = kInvalidCPUType;
info.endian = elf.endian;
info.pointerSize = elf.is64Bit ? 8 : 4;
info.osType = Platform::GetOSTypeName();
info.osVendor = Platform::GetOSVendorName();
return true;
}
示例2: GetProcessInfo
bool Platform::GetProcessInfo(ProcessId pid, ProcessInfo &info) {
HANDLE processHandle;
BOOL rc;
info.clear();
info.pid = pid;
processHandle =
OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
if (processHandle == nullptr) {
goto error;
}
// Get process name.
{
HMODULE firstModuleHandle;
DWORD bytesNeeded;
WCHAR processName[MAX_PATH];
rc = EnumProcessModules(processHandle, &firstModuleHandle,
sizeof(firstModuleHandle), &bytesNeeded);
if (!rc)
goto error;
rc = GetModuleBaseNameW(processHandle, firstModuleHandle, processName,
sizeof(processName));
if (!rc)
goto error;
info.name = WideToNarrowString(processName);
}
// Get process user ID.
{
HANDLE processToken;
std::vector<char> userInfoBuffer;
PTOKEN_USER userInfo;
DWORD bytesNeeded;
rc = OpenProcessToken(processHandle, TOKEN_QUERY, &processToken);
if (!rc)
goto error;
GetTokenInformation(processToken, TokenUser, userInfoBuffer.data(),
userInfoBuffer.size(), &bytesNeeded);
userInfoBuffer.resize(bytesNeeded);
rc = GetTokenInformation(processToken, TokenUser, userInfoBuffer.data(),
userInfoBuffer.size(), &bytesNeeded);
if (!rc) {
CloseHandle(processToken);
goto error;
}
userInfo = reinterpret_cast<PTOKEN_USER>(userInfoBuffer.data());
DWORD size = GetLengthSid(userInfo->User.Sid);
info.realUid = malloc(size);
CopySid(size, info.realUid, userInfo->User.Sid);
CloseHandle(processToken);
}
// TODO(sas): Fetch the process group ID. This looks like it's gonna
// require some additional work as a process on Windows doesn't have
// a single group but a list of group tokens instead.
CloseHandle(processHandle);
return true;
error:
if (processHandle != nullptr)
CloseHandle(processHandle);
return false;
}