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