process_posix.cc revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
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
5#include "base/process.h"
6
7#include <sys/types.h>
8#include <sys/time.h>
9#include <sys/resource.h>
10
11#include "base/process_util.h"
12#include "base/logging.h"
13
14namespace base {
15
16void Process::Close() {
17  process_ = 0;
18  // if the process wasn't terminated (so we waited) or the state
19  // wasn't already collected w/ a wait from process_utils, we're gonna
20  // end up w/ a zombie when it does finally exit.
21}
22
23void Process::Terminate(int result_code) {
24  // result_code isn't supportable.
25  if (!process_)
26    return;
27  // We don't wait here. It's the responsibility of other code to reap the
28  // child.
29  KillProcess(process_, result_code, false);
30}
31
32#if !defined(OS_LINUX)
33bool Process::IsProcessBackgrounded() const {
34  // See SetProcessBackgrounded().
35  return false;
36}
37
38bool Process::SetProcessBackgrounded(bool value) {
39  // POSIX only allows lowering the priority of a process, so if we
40  // were to lower it we wouldn't be able to raise it back to its initial
41  // priority.
42  return false;
43}
44#endif
45
46ProcessId Process::pid() const {
47  if (process_ == 0)
48    return 0;
49
50  return GetProcId(process_);
51}
52
53bool Process::is_current() const {
54  return process_ == GetCurrentProcessHandle();
55}
56
57// static
58Process Process::Current() {
59  return Process(GetCurrentProcessHandle());
60}
61
62int Process::GetPriority() const {
63  DCHECK(process_);
64  return getpriority(PRIO_PROCESS, process_);
65}
66
67}  // namspace base
68