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