1 // Copyright 2013 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/process/process_handle.h" 6 7 #include "base/files/file_util.h" 8 #include "base/numerics/safe_conversions.h" 9 #include "base/process/internal_linux.h" 10 #include "build/build_config.h" 11 #if BUILDFLAG(IS_AIX) 12 #include "base/process/internal_aix.h" 13 #endif 14 15 namespace base { 16 GetParentProcessId(ProcessHandle process)17ProcessId GetParentProcessId(ProcessHandle process) { 18 ProcessId pid = 19 #if BUILDFLAG(IS_AIX) 20 internalAIX::ReadProcStatsAndGetFieldAsInt64(process, 21 internalAIX::VM_PPID); 22 #else 23 checked_cast<ProcessId>(internal::ReadProcStatsAndGetFieldAsInt64( 24 process, internal::VM_PPID)); 25 #endif 26 // TODO(zijiehe): Returns 0 if |process| does not have a parent process. 27 if (pid) 28 return pid; 29 return -1; 30 } 31 GetProcessExecutablePath(ProcessHandle process)32FilePath GetProcessExecutablePath(ProcessHandle process) { 33 FilePath stat_file = internal::GetProcPidDir(process).Append("exe"); 34 FilePath exe_name; 35 if (!ReadSymbolicLink(stat_file, &exe_name)) { 36 // No such process. Happens frequently in e.g. TerminateAllChromeProcesses 37 return FilePath(); 38 } 39 return exe_name; 40 } 41 42 } // namespace base 43