OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_PROCESS_PROCESS_HANDLE_H_ | 5 #ifndef BASE_PROCESS_PROCESS_HANDLE_H_ |
6 #define BASE_PROCESS_PROCESS_HANDLE_H_ | 6 #define BASE_PROCESS_PROCESS_HANDLE_H_ |
7 | 7 |
8 #include <stdint.h> | |
danakj
2015/08/05 19:52:26
You want base/basictypes.h, instead of these.
rickyz (no longer on Chrome)
2015/08/13 23:16:55
Is that still the case? https://code.google.com/p/
| |
9 #include <sys/types.h> | |
10 | |
8 #include "base/base_export.h" | 11 #include "base/base_export.h" |
9 #include "base/basictypes.h" | |
10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
11 #include "build/build_config.h" | 13 #include "build/build_config.h" |
12 | 14 |
13 #include <sys/types.h> | |
14 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
15 #include <windows.h> | 16 #include <windows.h> |
16 #endif | 17 #endif |
17 | 18 |
18 namespace base { | 19 namespace base { |
19 | 20 |
20 // ProcessHandle is a platform specific type which represents the underlying OS | 21 // ProcessHandle is a platform specific type which represents the underlying OS |
21 // handle to a process. | 22 // handle to a process. |
22 // ProcessId is a number which identifies the process in the OS. | 23 // ProcessId is a number which identifies the process in the OS. |
23 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
24 typedef HANDLE ProcessHandle; | 25 typedef HANDLE ProcessHandle; |
25 typedef DWORD ProcessId; | 26 typedef DWORD ProcessId; |
26 typedef HANDLE UserTokenHandle; | 27 typedef HANDLE UserTokenHandle; |
27 const ProcessHandle kNullProcessHandle = NULL; | 28 const ProcessHandle kNullProcessHandle = NULL; |
28 const ProcessId kNullProcessId = 0; | 29 const ProcessId kNullProcessId = 0; |
29 #elif defined(OS_POSIX) | 30 #elif defined(OS_POSIX) |
30 // On POSIX, our ProcessHandle will just be the PID. | 31 // On POSIX, our ProcessHandle will just be the PID. |
31 typedef pid_t ProcessHandle; | 32 typedef pid_t ProcessHandle; |
32 typedef pid_t ProcessId; | 33 typedef pid_t ProcessId; |
33 const ProcessHandle kNullProcessHandle = 0; | 34 const ProcessHandle kNullProcessHandle = 0; |
34 const ProcessId kNullProcessId = 0; | 35 const ProcessId kNullProcessId = 0; |
35 #endif // defined(OS_WIN) | 36 #endif // defined(OS_WIN) |
36 | 37 |
38 // This is not a valid process ID on Linux (including Android), Mac, or Windows. | |
39 const uint32_t kInvalidUniqueId = 0; | |
danakj
2015/08/05 19:52:26
Does this need to be in the header? Can it move to
rickyz (no longer on Chrome)
2015/08/13 23:16:55
Don't think so, moved it into the anon namespace i
| |
40 | |
37 // Returns the id of the current process. | 41 // Returns the id of the current process. |
42 // Note that on some platforms, this is not guaranteed to be unique across | |
danakj
2015/08/05 19:52:26
Who would ever want to use this one?
rickyz (no longer on Chrome)
2015/08/13 23:16:55
GetCurrentProcId is still useful for APIs that nee
| |
43 // processes (use GetUniqueIdForProcess if uniqueness is required). | |
38 BASE_EXPORT ProcessId GetCurrentProcId(); | 44 BASE_EXPORT ProcessId GetCurrentProcId(); |
39 | 45 |
46 // Returns a unique ID for the current process. The ID will be unique across all | |
47 // currently running processes within the chrome session, but note that IDs of | |
48 // terminated processes may be reused. This defaults to the process's process | |
49 // ID, but may return a different value if SetUniqueIdForProcess has been | |
50 // called. | |
51 BASE_EXPORT uint32_t GetUniqueIdForProcess(); | |
52 | |
53 // Sets the unique ID for the current process. |unique_id| may not be | |
54 // kInvalidUniqueId. Not thread safe. | |
55 // WARNING: To avoid inconsistent results from GetUniqueIdForProcess, this | |
56 // should only be called very early after process startup - ideally as soon | |
57 // after process creation as possible. | |
58 BASE_EXPORT void SetUniqueIdForProcess(uint32_t unique_id); | |
59 | |
40 // Returns the ProcessHandle of the current process. | 60 // Returns the ProcessHandle of the current process. |
41 BASE_EXPORT ProcessHandle GetCurrentProcessHandle(); | 61 BASE_EXPORT ProcessHandle GetCurrentProcessHandle(); |
42 | 62 |
43 // Returns the unique ID for the specified process. This is functionally the | 63 // Returns the process ID for the specified process. This is functionally the |
44 // same as Windows' GetProcessId(), but works on versions of Windows before | 64 // same as Windows' GetProcessId(), but works on versions of Windows before Win |
45 // Win XP SP1 as well. | 65 // XP SP1 as well. |
46 // DEPRECATED. New code should be using Process::Pid() instead. | 66 // DEPRECATED. New code should be using Process::Pid() instead. |
67 // Note that on some platforms, this is not guaranteed to be unique across | |
danakj
2015/08/05 19:52:26
Does this mean Process:Pid() can be non-unique (al
rickyz (no longer on Chrome)
2015/08/13 23:16:55
It does, but as mentioned above, there are situati
danakj
2015/09/15 18:06:39
i think i'm not understanding something: if you're
| |
68 // processes. | |
47 BASE_EXPORT ProcessId GetProcId(ProcessHandle process); | 69 BASE_EXPORT ProcessId GetProcId(ProcessHandle process); |
48 | 70 |
49 #if defined(OS_POSIX) | 71 #if defined(OS_POSIX) |
50 // Returns the path to the executable of the given process. | 72 // Returns the path to the executable of the given process. |
51 BASE_EXPORT FilePath GetProcessExecutablePath(ProcessHandle process); | 73 BASE_EXPORT FilePath GetProcessExecutablePath(ProcessHandle process); |
52 | 74 |
53 // Returns the ID for the parent of the given process. | 75 // Returns the ID for the parent of the given process. |
54 BASE_EXPORT ProcessId GetParentProcessId(ProcessHandle process); | 76 BASE_EXPORT ProcessId GetParentProcessId(ProcessHandle process); |
55 #endif | 77 #endif |
56 | 78 |
57 } // namespace base | 79 } // namespace base |
58 | 80 |
59 #endif // BASE_PROCESS_PROCESS_HANDLE_H_ | 81 #endif // BASE_PROCESS_PROCESS_HANDLE_H_ |
OLD | NEW |