[email protected] | 0b100bc8b | 2008-10-14 20:49:16 | [diff] [blame] | 1 | // Copyright (c) 2008 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. | ||||
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" |
12 | |||||
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 13 | namespace base { |
14 | |||||
15 | void Process::Close() { | ||||
16 | process_ = 0; | ||||
[email protected] | 276aa6a | 2009-10-29 17:43:44 | [diff] [blame] | 17 | // if the process wasn't terminated (so we waited) or the state |
[email protected] | 1a781364 | 2009-02-05 19:22:01 | [diff] [blame] | 18 | // wasn't already collected w/ a wait from process_utils, we're gonna |
19 | // end up w/ a zombie when it does finally exit. | ||||
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 20 | } |
21 | |||||
[email protected] | af77384 | 2008-11-14 03:48:25 | [diff] [blame] | 22 | void Process::Terminate(int result_code) { |
[email protected] | 1a781364 | 2009-02-05 19:22:01 | [diff] [blame] | 23 | // result_code isn't supportable. |
24 | if (!process_) | ||||
25 | return; | ||||
[email protected] | 140a7cd | 2009-04-28 01:37:23 | [diff] [blame] | 26 | // We don't wait here. It's the responsibility of other code to reap the |
27 | // child. | ||||
28 | KillProcess(process_, result_code, false); | ||||
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 29 | } |
30 | |||||
[email protected] | 276aa6a | 2009-10-29 17:43:44 | [diff] [blame] | 31 | #if !defined(OS_LINUX) |
[email protected] | 2f15de4 | 2008-11-11 22:35:19 | [diff] [blame] | 32 | bool Process::IsProcessBackgrounded() const { |
[email protected] | 276aa6a | 2009-10-29 17:43:44 | [diff] [blame] | 33 | // See SetProcessBackgrounded(). |
[email protected] | 0b100bc8b | 2008-10-14 20:49:16 | [diff] [blame] | 34 | return false; |
35 | } | ||||
36 | |||||
37 | bool Process::SetProcessBackgrounded(bool value) { | ||||
[email protected] | 276aa6a | 2009-10-29 17:43:44 | [diff] [blame] | 38 | // POSIX only allows lowering the priority of a process, so if we |
39 | // were to lower it we wouldn't be able to raise it back to its initial | ||||
40 | // priority. | ||||
41 | return false; | ||||
[email protected] | 0b100bc8b | 2008-10-14 20:49:16 | [diff] [blame] | 42 | } |
[email protected] | 276aa6a | 2009-10-29 17:43:44 | [diff] [blame] | 43 | #endif |
[email protected] | 0b100bc8b | 2008-10-14 20:49:16 | [diff] [blame] | 44 | |
[email protected] | 43cf325 | 2009-04-01 09:19:37 | [diff] [blame] | 45 | ProcessId Process::pid() const { |
[email protected] | 0b100bc8b | 2008-10-14 20:49:16 | [diff] [blame] | 46 | if (process_ == 0) |
47 | return 0; | ||||
48 | |||||
[email protected] | 9963aaa | 2008-11-14 04:01:35 | [diff] [blame] | 49 | return GetProcId(process_); |
[email protected] | 0b100bc8b | 2008-10-14 20:49:16 | [diff] [blame] | 50 | } |
51 | |||||
52 | bool Process::is_current() const { | ||||
[email protected] | 9963aaa | 2008-11-14 04:01:35 | [diff] [blame] | 53 | return process_ == GetCurrentProcessHandle(); |
[email protected] | 0b100bc8b | 2008-10-14 20:49:16 | [diff] [blame] | 54 | } |
55 | |||||
56 | // static | ||||
57 | Process Process::Current() { | ||||
[email protected] | 9963aaa | 2008-11-14 04:01:35 | [diff] [blame] | 58 | return Process(GetCurrentProcessHandle()); |
[email protected] | 0b100bc8b | 2008-10-14 20:49:16 | [diff] [blame] | 59 | } |
60 | |||||
[email protected] | 276aa6a | 2009-10-29 17:43:44 | [diff] [blame] | 61 | int Process::GetPriority() const { |
62 | DCHECK(process_); | ||||
63 | return getpriority(PRIO_PROCESS, process_); | ||||
64 | } | ||||
65 | |||||
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 66 | } // namspace base |