1 // Copyright (c) 2011 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.
5 #include "base/process_util.h"
12 #include <sys/sysctl.h>
14 #include <sys/types.h>
20 #include "base/logging.h"
21 #include "base/string_tokenizer.h"
22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_split.h"
24 #include "base/strings/string_util.h"
25 #include "base/sys_info.h"
29 ProcessId
GetParentProcessId(ProcessHandle process
) {
30 struct kinfo_proc info
;
32 int mib
[] = { CTL_KERN
, KERN_PROC
, KERN_PROC_PID
, process
};
34 if (sysctl(mib
, arraysize(mib
), &info
, &length
, NULL
, 0) < 0)
40 FilePath
GetProcessExecutablePath(ProcessHandle process
) {
41 char pathname
[PATH_MAX
];
43 int mib
[] = { CTL_KERN
, KERN_PROC
, KERN_PROC_PATHNAME
, process
};
45 length
= sizeof(pathname
);
47 if (sysctl(mib
, arraysize(mib
), pathname
, &length
, NULL
, 0) < 0 ||
52 return FilePath(std::string(pathname
));