blob: 904884a5945c10384e67f81816a78cbf25d9c177 [file] [log] [blame]
[email protected]0b100bc8b2008-10-14 20:49:161// 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]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"
12
[email protected]176aa482008-11-14 03:25:1513namespace base {
14
15void Process::Close() {
16 process_ = 0;
[email protected]276aa6a2009-10-29 17:43:4417 // if the process wasn't terminated (so we waited) or the state
[email protected]1a7813642009-02-05 19:22:0118 // 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]176aa482008-11-14 03:25:1520}
21
[email protected]af773842008-11-14 03:48:2522void Process::Terminate(int result_code) {
[email protected]1a7813642009-02-05 19:22:0123 // result_code isn't supportable.
24 if (!process_)
25 return;
[email protected]140a7cd2009-04-28 01:37:2326 // 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]176aa482008-11-14 03:25:1529}
30
[email protected]276aa6a2009-10-29 17:43:4431#if !defined(OS_LINUX)
[email protected]2f15de42008-11-11 22:35:1932bool Process::IsProcessBackgrounded() const {
[email protected]276aa6a2009-10-29 17:43:4433 // See SetProcessBackgrounded().
[email protected]0b100bc8b2008-10-14 20:49:1634 return false;
35}
36
37bool Process::SetProcessBackgrounded(bool value) {
[email protected]276aa6a2009-10-29 17:43:4438 // 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]0b100bc8b2008-10-14 20:49:1642}
[email protected]276aa6a2009-10-29 17:43:4443#endif
[email protected]0b100bc8b2008-10-14 20:49:1644
[email protected]43cf3252009-04-01 09:19:3745ProcessId Process::pid() const {
[email protected]0b100bc8b2008-10-14 20:49:1646 if (process_ == 0)
47 return 0;
48
[email protected]9963aaa2008-11-14 04:01:3549 return GetProcId(process_);
[email protected]0b100bc8b2008-10-14 20:49:1650}
51
52bool Process::is_current() const {
[email protected]9963aaa2008-11-14 04:01:3553 return process_ == GetCurrentProcessHandle();
[email protected]0b100bc8b2008-10-14 20:49:1654}
55
56// static
57Process Process::Current() {
[email protected]9963aaa2008-11-14 04:01:3558 return Process(GetCurrentProcessHandle());
[email protected]0b100bc8b2008-10-14 20:49:1659}
60
[email protected]276aa6a2009-10-29 17:43:4461int Process::GetPriority() const {
62 DCHECK(process_);
63 return getpriority(PRIO_PROCESS, process_);
64}
65
[email protected]176aa482008-11-14 03:25:1566} // namspace base