| 6 |
| 7 | #include "base/files/file_util.h" |
| 8 | #include "base/process/internal_linux.h" |
| 9 | #if defined(OS_AIX) |
| 10 | #include "base/process/internal_aix.h" |
| 11 | #endif |
| 12 |
| 13 | namespace base { |
| 14 |
| 15 | ProcessId GetParentProcessId(ProcessHandle process) { |
| 16 | ProcessId pid = |
| 17 | #if defined(OS_AIX) |
| 18 | internalAIX::ReadProcStatsAndGetFieldAsInt64(process, |
| 19 | internalAIX::VM_PPID); |
| 20 | #else |
| 21 | internal::ReadProcStatsAndGetFieldAsInt64(process, internal::VM_PPID); |
| 22 | #endif |
| 23 | // TODO(zijiehe): Returns 0 if |process| does not have a parent process. |
| 24 | if (pid) |
| 25 | return pid; |
| 26 | return -1; |
| 27 | } |
| 28 |
| 29 | FilePath GetProcessExecutablePath(ProcessHandle process) { |
| 30 | FilePath stat_file = internal::GetProcPidDir(process).Append("exe"); |
| 31 | FilePath exe_name; |
| 32 | if (!ReadSymbolicLink(stat_file, &exe_name)) { |
| 33 | // No such process. Happens frequently in e.g. TerminateAllChromeProcesses |
| 34 | return FilePath(); |
| 35 | } |
| 36 | return exe_name; |
| 37 | } |
| 38 |
| 39 | } // namespace base |
| 40 |