process_handle_linux.cc 847 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "butil/process/process_handle.h"
  5. #include "butil/file_util.h"
  6. #include "butil/process/internal_linux.h"
  7. namespace butil {
  8. ProcessId GetParentProcessId(ProcessHandle process) {
  9. ProcessId pid =
  10. internal::ReadProcStatsAndGetFieldAsInt64(process, internal::VM_PPID);
  11. if (pid)
  12. return pid;
  13. return -1;
  14. }
  15. FilePath GetProcessExecutablePath(ProcessHandle process) {
  16. FilePath stat_file = internal::GetProcPidDir(process).Append("exe");
  17. FilePath exe_name;
  18. if (!ReadSymbolicLink(stat_file, &exe_name)) {
  19. // No such process. Happens frequently in e.g. TerminateAllChromeProcesses
  20. return FilePath();
  21. }
  22. return exe_name;
  23. }
  24. } // namespace butil