[email protected] | 8a42080 | 2011-12-02 16:14:46 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 0b100bc8b | 2008-10-14 20:49:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 66700d4 | 2010-03-10 07:46:43 | [diff] [blame] | 5 | #include "base/process.h" |
6 | |||||
7 | #include <sys/types.h> | ||||
8 | #include <sys/time.h> | ||||
[email protected] | 276aa6a | 2009-10-29 17:43:44 | [diff] [blame] | 9 | #include <sys/resource.h> |
10 | |||||
[email protected] | 0b100bc8b | 2008-10-14 20:49:16 | [diff] [blame] | 11 | #include "base/process_util.h" |
[email protected] | 5d91c9e | 2010-07-28 17:25:28 | [diff] [blame] | 12 | #include "base/logging.h" |
[email protected] | 0b100bc8b | 2008-10-14 20:49:16 | [diff] [blame] | 13 | |
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 14 | namespace base { |
15 | |||||
[email protected] | b7d0820 | 2011-01-25 17:29:39 | [diff] [blame] | 16 | // static |
17 | Process Process::Current() { | ||||
18 | return Process(GetCurrentProcessHandle()); | ||||
19 | } | ||||
20 | |||||
21 | ProcessId Process::pid() const { | ||||
22 | if (process_ == 0) | ||||
23 | return 0; | ||||
24 | |||||
25 | return GetProcId(process_); | ||||
26 | } | ||||
27 | |||||
28 | bool Process::is_current() const { | ||||
29 | return process_ == GetCurrentProcessHandle(); | ||||
30 | } | ||||
31 | |||||
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 32 | void Process::Close() { |
33 | process_ = 0; | ||||
[email protected] | 276aa6a | 2009-10-29 17:43:44 | [diff] [blame] | 34 | // if the process wasn't terminated (so we waited) or the state |
[email protected] | 1a781364 | 2009-02-05 19:22:01 | [diff] [blame] | 35 | // wasn't already collected w/ a wait from process_utils, we're gonna |
36 | // end up w/ a zombie when it does finally exit. | ||||
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 37 | } |
38 | |||||
[email protected] | af77384 | 2008-11-14 03:48:25 | [diff] [blame] | 39 | void Process::Terminate(int result_code) { |
[email protected] | 1a781364 | 2009-02-05 19:22:01 | [diff] [blame] | 40 | // result_code isn't supportable. |
41 | if (!process_) | ||||
42 | return; | ||||
[email protected] | 140a7cd | 2009-04-28 01:37:23 | [diff] [blame] | 43 | // We don't wait here. It's the responsibility of other code to reap the |
44 | // child. | ||||
45 | KillProcess(process_, result_code, false); | ||||
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 46 | } |
47 | |||||
[email protected] | 276aa6a | 2009-10-29 17:43:44 | [diff] [blame] | 48 | #if !defined(OS_LINUX) |
[email protected] | 2f15de4 | 2008-11-11 22:35:19 | [diff] [blame] | 49 | bool Process::IsProcessBackgrounded() const { |
[email protected] | 276aa6a | 2009-10-29 17:43:44 | [diff] [blame] | 50 | // See SetProcessBackgrounded(). |
[email protected] | 0b100bc8b | 2008-10-14 20:49:16 | [diff] [blame] | 51 | return false; |
52 | } | ||||
53 | |||||
54 | bool Process::SetProcessBackgrounded(bool value) { | ||||
[email protected] | 276aa6a | 2009-10-29 17:43:44 | [diff] [blame] | 55 | // POSIX only allows lowering the priority of a process, so if we |
56 | // were to lower it we wouldn't be able to raise it back to its initial | ||||
57 | // priority. | ||||
58 | return false; | ||||
[email protected] | 0b100bc8b | 2008-10-14 20:49:16 | [diff] [blame] | 59 | } |
[email protected] | 8a42080 | 2011-12-02 16:14:46 | [diff] [blame] | 60 | |
61 | // static | ||||
62 | bool Process::CanBackgroundProcesses() { | ||||
63 | return false; | ||||
64 | } | ||||
65 | |||||
[email protected] | 276aa6a | 2009-10-29 17:43:44 | [diff] [blame] | 66 | #endif |
[email protected] | 0b100bc8b | 2008-10-14 20:49:16 | [diff] [blame] | 67 | |
[email protected] | 276aa6a | 2009-10-29 17:43:44 | [diff] [blame] | 68 | int Process::GetPriority() const { |
69 | DCHECK(process_); | ||||
70 | return getpriority(PRIO_PROCESS, process_); | ||||
71 | } | ||||
72 | |||||
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 73 | } // namspace base |