blob: 20e623c3fdd9ba7ee153b90595202c2edd58adeb [file] [log] [blame]
[email protected]8a420802011-12-02 16:14:461// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]0b100bc8b2008-10-14 20:49:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]66700d42010-03-10 07:46:435#include "base/process.h"
6
7#include <sys/types.h>
8#include <sys/time.h>
[email protected]276aa6a2009-10-29 17:43:449#include <sys/resource.h>
10
[email protected]0b100bc8b2008-10-14 20:49:1611#include "base/process_util.h"
[email protected]5d91c9e2010-07-28 17:25:2812#include "base/logging.h"
[email protected]0b100bc8b2008-10-14 20:49:1613
[email protected]176aa482008-11-14 03:25:1514namespace base {
15
[email protected]b7d08202011-01-25 17:29:3916// static
17Process Process::Current() {
18 return Process(GetCurrentProcessHandle());
19}
20
21ProcessId Process::pid() const {
22 if (process_ == 0)
23 return 0;
24
25 return GetProcId(process_);
26}
27
28bool Process::is_current() const {
29 return process_ == GetCurrentProcessHandle();
30}
31
[email protected]176aa482008-11-14 03:25:1532void Process::Close() {
33 process_ = 0;
[email protected]276aa6a2009-10-29 17:43:4434 // if the process wasn't terminated (so we waited) or the state
[email protected]1a7813642009-02-05 19:22:0135 // 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]176aa482008-11-14 03:25:1537}
38
[email protected]af773842008-11-14 03:48:2539void Process::Terminate(int result_code) {
[email protected]1a7813642009-02-05 19:22:0140 // result_code isn't supportable.
41 if (!process_)
42 return;
[email protected]140a7cd2009-04-28 01:37:2343 // 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]176aa482008-11-14 03:25:1546}
47
[email protected]276aa6a2009-10-29 17:43:4448#if !defined(OS_LINUX)
[email protected]2f15de42008-11-11 22:35:1949bool Process::IsProcessBackgrounded() const {
[email protected]276aa6a2009-10-29 17:43:4450 // See SetProcessBackgrounded().
[email protected]0b100bc8b2008-10-14 20:49:1651 return false;
52}
53
54bool Process::SetProcessBackgrounded(bool value) {
[email protected]276aa6a2009-10-29 17:43:4455 // 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]0b100bc8b2008-10-14 20:49:1659}
[email protected]8a420802011-12-02 16:14:4660
61// static
62bool Process::CanBackgroundProcesses() {
63 return false;
64}
65
[email protected]276aa6a2009-10-29 17:43:4466#endif
[email protected]0b100bc8b2008-10-14 20:49:1667
[email protected]276aa6a2009-10-29 17:43:4468int Process::GetPriority() const {
69 DCHECK(process_);
70 return getpriority(PRIO_PROCESS, process_);
71}
72
[email protected]176aa482008-11-14 03:25:1573} // namspace base