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 // This file contains routines to kill processes and get the exit code and | 5 // This file contains routines to kill processes and get the exit code and |
6 // termination status. | 6 // termination status. |
7 | 7 |
8 #ifndef BASE_PROCESS_KILL_H_ | 8 #ifndef BASE_PROCESS_KILL_H_ |
9 #define BASE_PROCESS_KILL_H_ | 9 #define BASE_PROCESS_KILL_H_ |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // for the process to be actually terminated before returning. | 50 // for the process to be actually terminated before returning. |
51 // Returns true if this is successful, false otherwise. | 51 // Returns true if this is successful, false otherwise. |
52 BASE_EXPORT bool KillProcess(ProcessHandle process, int exit_code, bool wait); | 52 BASE_EXPORT bool KillProcess(ProcessHandle process, int exit_code, bool wait); |
53 | 53 |
54 #if defined(OS_POSIX) | 54 #if defined(OS_POSIX) |
55 // Attempts to kill the process group identified by |process_group_id|. Returns | 55 // Attempts to kill the process group identified by |process_group_id|. Returns |
56 // true on success. | 56 // true on success. |
57 BASE_EXPORT bool KillProcessGroup(ProcessHandle process_group_id); | 57 BASE_EXPORT bool KillProcessGroup(ProcessHandle process_group_id); |
58 #endif // defined(OS_POSIX) | 58 #endif // defined(OS_POSIX) |
59 | 59 |
60 #if defined(OS_WIN) | |
61 BASE_EXPORT bool KillProcessById(ProcessId process_id, | |
62 int exit_code, | |
63 bool wait); | |
64 #endif // defined(OS_WIN) | |
65 | |
66 // Get the termination status of the process by interpreting the | 60 // Get the termination status of the process by interpreting the |
67 // circumstances of the child process' death. |exit_code| is set to | 61 // circumstances of the child process' death. |exit_code| is set to |
68 // the status returned by waitpid() on POSIX, and from | 62 // the status returned by waitpid() on POSIX, and from |
69 // GetExitCodeProcess() on Windows. |exit_code| may be NULL if the | 63 // GetExitCodeProcess() on Windows. |exit_code| may be NULL if the |
70 // caller is not interested in it. Note that on Linux, this function | 64 // caller is not interested in it. Note that on Linux, this function |
71 // will only return a useful result the first time it is called after | 65 // will only return a useful result the first time it is called after |
72 // the child exits (because it will reap the child and the information | 66 // the child exits (because it will reap the child and the information |
73 // will no longer be available). | 67 // will no longer be available). |
74 BASE_EXPORT TerminationStatus GetTerminationStatus(ProcessHandle handle, | 68 BASE_EXPORT TerminationStatus GetTerminationStatus(ProcessHandle handle, |
75 int* exit_code); | 69 int* exit_code); |
(...skipping 11 matching lines...) Expand all Loading... |
87 // termination status. | 81 // termination status. |
88 // | 82 // |
89 // Note that it is not an option to call WaitForExitCode and then | 83 // Note that it is not an option to call WaitForExitCode and then |
90 // GetTerminationStatus as the child will be reaped when WaitForExitCode | 84 // GetTerminationStatus as the child will be reaped when WaitForExitCode |
91 // returns, and this information will be lost. | 85 // returns, and this information will be lost. |
92 // | 86 // |
93 BASE_EXPORT TerminationStatus GetKnownDeadTerminationStatus( | 87 BASE_EXPORT TerminationStatus GetKnownDeadTerminationStatus( |
94 ProcessHandle handle, int* exit_code); | 88 ProcessHandle handle, int* exit_code); |
95 #endif // defined(OS_POSIX) | 89 #endif // defined(OS_POSIX) |
96 | 90 |
97 // Waits for process to exit. On POSIX systems, if the process hasn't been | |
98 // signaled then puts the exit code in |exit_code|; otherwise it's considered | |
99 // a failure. On Windows |exit_code| is always filled. Returns true on success, | |
100 // and closes |handle| in any case. | |
101 BASE_EXPORT bool WaitForExitCode(ProcessHandle handle, int* exit_code); | |
102 | |
103 // Waits for process to exit. If it did exit within |timeout_milliseconds|, | |
104 // then puts the exit code in |exit_code|, and returns true. | |
105 // In POSIX systems, if the process has been signaled then |exit_code| is set | |
106 // to -1. Returns false on failure (the caller is then responsible for closing | |
107 // |handle|). | |
108 // The caller is always responsible for closing the |handle|. | |
109 BASE_EXPORT bool WaitForExitCodeWithTimeout(ProcessHandle handle, | |
110 int* exit_code, | |
111 base::TimeDelta timeout); | |
112 | |
113 // Wait for all the processes based on the named executable to exit. If filter | 91 // Wait for all the processes based on the named executable to exit. If filter |
114 // is non-null, then only processes selected by the filter are waited on. | 92 // is non-null, then only processes selected by the filter are waited on. |
115 // Returns after all processes have exited or wait_milliseconds have expired. | 93 // Returns after all processes have exited or wait_milliseconds have expired. |
116 // Returns true if all the processes exited, false otherwise. | 94 // Returns true if all the processes exited, false otherwise. |
117 BASE_EXPORT bool WaitForProcessesToExit( | 95 BASE_EXPORT bool WaitForProcessesToExit( |
118 const FilePath::StringType& executable_name, | 96 const FilePath::StringType& executable_name, |
119 base::TimeDelta wait, | 97 base::TimeDelta wait, |
120 const ProcessFilter* filter); | 98 const ProcessFilter* filter); |
121 | 99 |
122 // Waits a certain amount of time (can be 0) for all the processes with a given | 100 // Waits a certain amount of time (can be 0) for all the processes with a given |
(...skipping 25 matching lines...) Expand all Loading... |
148 | 126 |
149 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 127 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
150 // The nicer version of EnsureProcessTerminated() that is patient and will | 128 // The nicer version of EnsureProcessTerminated() that is patient and will |
151 // wait for |pid| to finish and then reap it. | 129 // wait for |pid| to finish and then reap it. |
152 BASE_EXPORT void EnsureProcessGetsReaped(ProcessId pid); | 130 BASE_EXPORT void EnsureProcessGetsReaped(ProcessId pid); |
153 #endif | 131 #endif |
154 | 132 |
155 } // namespace base | 133 } // namespace base |
156 | 134 |
157 #endif // BASE_PROCESS_KILL_H_ | 135 #endif // BASE_PROCESS_KILL_H_ |
OLD | NEW |