OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 #include "base/process/process.h" | 5 #include "base/process/process.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <sys/resource.h> | 9 #include <sys/resource.h> |
10 #include <sys/wait.h> | 10 #include <sys/wait.h> |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 176 |
177 return true; | 177 return true; |
178 } | 178 } |
179 #endif // OS_MACOSX | 179 #endif // OS_MACOSX |
180 | 180 |
181 bool WaitForExitWithTimeoutImpl(base::ProcessHandle handle, | 181 bool WaitForExitWithTimeoutImpl(base::ProcessHandle handle, |
182 int* exit_code, | 182 int* exit_code, |
183 base::TimeDelta timeout) { | 183 base::TimeDelta timeout) { |
184 base::ProcessHandle parent_pid = base::GetParentProcessId(handle); | 184 base::ProcessHandle parent_pid = base::GetParentProcessId(handle); |
185 base::ProcessHandle our_pid = base::GetCurrentProcessHandle(); | 185 base::ProcessHandle our_pid = base::GetCurrentProcessHandle(); |
| 186 |
186 if (parent_pid != our_pid) { | 187 if (parent_pid != our_pid) { |
187 #if defined(OS_MACOSX) | 188 #if defined(OS_MACOSX) |
188 // On Mac we can wait on non child processes. | 189 // On Mac we can wait on non child processes. |
189 return WaitForSingleNonChildProcess(handle, timeout); | 190 return WaitForSingleNonChildProcess(handle, timeout); |
190 #else | 191 #else |
191 // Currently on Linux we can't handle non child processes. | 192 // Currently on Linux we can't handle non child processes. |
192 NOTIMPLEMENTED(); | 193 NOTIMPLEMENTED(); |
193 #endif // OS_MACOSX | 194 #endif // OS_MACOSX |
194 } | 195 } |
195 | 196 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 // On POSIX there are no privileges to set. | 250 // On POSIX there are no privileges to set. |
250 return Open(pid); | 251 return Open(pid); |
251 } | 252 } |
252 | 253 |
253 // static | 254 // static |
254 Process Process::DeprecatedGetProcessFromHandle(ProcessHandle handle) { | 255 Process Process::DeprecatedGetProcessFromHandle(ProcessHandle handle) { |
255 DCHECK_NE(handle, GetCurrentProcessHandle()); | 256 DCHECK_NE(handle, GetCurrentProcessHandle()); |
256 return Process(handle); | 257 return Process(handle); |
257 } | 258 } |
258 | 259 |
259 #if !defined(OS_LINUX) && !defined(OS_MACOSX) | 260 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_AIX) |
260 // static | 261 // static |
261 bool Process::CanBackgroundProcesses() { | 262 bool Process::CanBackgroundProcesses() { |
262 return false; | 263 return false; |
263 } | 264 } |
264 #endif // !defined(OS_LINUX) && !defined(OS_MACOSX) | 265 #endif // !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_AIX) |
265 | 266 |
266 // static | 267 // static |
267 void Process::TerminateCurrentProcessImmediately(int exit_code) { | 268 void Process::TerminateCurrentProcessImmediately(int exit_code) { |
268 _exit(exit_code); | 269 _exit(exit_code); |
269 } | 270 } |
270 | 271 |
271 bool Process::IsValid() const { | 272 bool Process::IsValid() const { |
272 return process_ != kNullProcessHandle; | 273 return process_ != kNullProcessHandle; |
273 } | 274 } |
274 | 275 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 return WaitForExitWithTimeout(TimeDelta::Max(), exit_code); | 359 return WaitForExitWithTimeout(TimeDelta::Max(), exit_code); |
359 } | 360 } |
360 | 361 |
361 bool Process::WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) const { | 362 bool Process::WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) const { |
362 // Record the event that this thread is blocking upon (for hang diagnosis). | 363 // Record the event that this thread is blocking upon (for hang diagnosis). |
363 base::debug::ScopedProcessWaitActivity process_activity(this); | 364 base::debug::ScopedProcessWaitActivity process_activity(this); |
364 | 365 |
365 return WaitForExitWithTimeoutImpl(Handle(), exit_code, timeout); | 366 return WaitForExitWithTimeoutImpl(Handle(), exit_code, timeout); |
366 } | 367 } |
367 | 368 |
368 #if !defined(OS_LINUX) && !defined(OS_MACOSX) | 369 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_AIX) |
369 bool Process::IsProcessBackgrounded() const { | 370 bool Process::IsProcessBackgrounded() const { |
370 // See SetProcessBackgrounded(). | 371 // See SetProcessBackgrounded(). |
371 DCHECK(IsValid()); | 372 DCHECK(IsValid()); |
372 return false; | 373 return false; |
373 } | 374 } |
374 | 375 |
375 bool Process::SetProcessBackgrounded(bool value) { | 376 bool Process::SetProcessBackgrounded(bool value) { |
376 // Not implemented for POSIX systems other than Linux and Mac. With POSIX, if | 377 // Not implemented for POSIX systems other than Linux and Mac. With POSIX, if |
377 // we were to lower the process priority we wouldn't be able to raise it back | 378 // we were to lower the process priority we wouldn't be able to raise it back |
378 // to its initial priority. | 379 // to its initial priority. |
379 NOTIMPLEMENTED(); | 380 NOTIMPLEMENTED(); |
380 return false; | 381 return false; |
381 } | 382 } |
382 #endif // !defined(OS_LINUX) && !defined(OS_MACOSX) | 383 #endif // !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_AIX) |
383 | 384 |
384 int Process::GetPriority() const { | 385 int Process::GetPriority() const { |
385 DCHECK(IsValid()); | 386 DCHECK(IsValid()); |
386 return getpriority(PRIO_PROCESS, process_); | 387 return getpriority(PRIO_PROCESS, process_); |
387 } | 388 } |
388 | 389 |
389 } // namespace base | 390 } // namespace base |
OLD | NEW |