Roll src/third_party/skia b3eb687:c6f3e2c
[chromium-blink-merge.git] / base / process / process_posix.cc
blobea8fd8cea1e7d95e2c283fe72099dc0fd36ce8af
1 // Copyright (c) 2011 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.
5 #include "base/process/process.h"
7 #include <sys/resource.h>
8 #include <sys/time.h>
9 #include <sys/types.h>
11 #include "base/logging.h"
12 #include "base/process/kill.h"
14 namespace base {
16 Process::Process(ProcessHandle handle) : process_(handle) {
17 CHECK_NE(handle, GetCurrentProcessHandle());
20 Process::Process(RValue other)
21 : process_(other.object->process_) {
22 other.object->Close();
25 Process& Process::operator=(RValue other) {
26 if (this != other.object) {
27 process_ = other.object->process_;
28 other.object->Close();
30 return *this;
33 // static
34 Process Process::Current() {
35 Process process;
36 process.process_ = GetCurrentProcessHandle();
37 return process.Pass();
40 #if !defined(OS_LINUX)
41 // static
42 bool Process::CanBackgroundProcesses() {
43 return false;
45 #endif // !defined(OS_LINUX)
47 bool Process::IsValid() const {
48 return process_ != kNullProcessHandle;
51 ProcessHandle Process::Handle() const {
52 return process_;
55 Process Process::Duplicate() const {
56 if (is_current())
57 return Current();
59 return Process(process_);
62 ProcessId Process::pid() const {
63 DCHECK(IsValid());
64 return GetProcId(process_);
67 bool Process::is_current() const {
68 return process_ == GetCurrentProcessHandle();
71 void Process::Close() {
72 process_ = kNullProcessHandle;
73 // if the process wasn't terminated (so we waited) or the state
74 // wasn't already collected w/ a wait from process_utils, we're gonna
75 // end up w/ a zombie when it does finally exit.
78 void Process::Terminate(int result_code) {
79 // result_code isn't supportable.
80 DCHECK(IsValid());
81 // We don't wait here. It's the responsibility of other code to reap the
82 // child.
83 KillProcess(process_, result_code, false);
86 #if !defined(OS_LINUX)
87 bool Process::IsProcessBackgrounded() const {
88 // See SetProcessBackgrounded().
89 DCHECK(IsValid());
90 return false;
93 bool Process::SetProcessBackgrounded(bool value) {
94 // POSIX only allows lowering the priority of a process, so if we
95 // were to lower it we wouldn't be able to raise it back to its initial
96 // priority.
97 DCHECK(IsValid());
98 return false;
100 #endif // !defined(OS_LINUX)
102 int Process::GetPriority() const {
103 DCHECK(IsValid());
104 return getpriority(PRIO_PROCESS, process_);
107 } // namspace base