当前位置: 首页>>代码示例>>C++>>正文


C++ ProcessInfo::clear方法代码示例

本文整理汇总了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;
}
开发者ID:cosql,项目名称:ds2,代码行数:41,代码来源:ProcFS.cpp

示例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;
}
开发者ID:fjricci,项目名称:ds2,代码行数:78,代码来源:Platform.cpp


注:本文中的ProcessInfo::clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。