OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/process/process.h" | 5 #include "base/process/process.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <signal.h> | 8 #include <signal.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <sys/resource.h> | 10 #include <sys/resource.h> |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 return true; | 178 return true; |
179 } | 179 } |
180 #endif // OS_MACOSX | 180 #endif // OS_MACOSX |
181 | 181 |
182 bool WaitForExitWithTimeoutImpl(base::ProcessHandle handle, | 182 bool WaitForExitWithTimeoutImpl(base::ProcessHandle handle, |
183 int* exit_code, | 183 int* exit_code, |
184 base::TimeDelta timeout) { | 184 base::TimeDelta timeout) { |
185 base::ProcessHandle parent_pid = base::GetParentProcessId(handle); | 185 base::ProcessHandle parent_pid = base::GetParentProcessId(handle); |
186 base::ProcessHandle our_pid = base::GetCurrentProcessHandle(); | 186 base::ProcessHandle our_pid = base::GetCurrentProcessHandle(); |
| 187 |
187 if (parent_pid != our_pid) { | 188 if (parent_pid != our_pid) { |
188 #if defined(OS_MACOSX) | 189 #if defined(OS_MACOSX) |
189 // On Mac we can wait on non child processes. | 190 // On Mac we can wait on non child processes. |
190 return WaitForSingleNonChildProcess(handle, timeout); | 191 return WaitForSingleNonChildProcess(handle, timeout); |
191 #else | 192 #else |
192 // Currently on Linux we can't handle non child processes. | 193 // Currently on Linux we can't handle non child processes. |
193 NOTIMPLEMENTED(); | 194 NOTIMPLEMENTED(); |
194 #endif // OS_MACOSX | 195 #endif // OS_MACOSX |
195 } | 196 } |
196 | 197 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // On POSIX there are no privileges to set. | 251 // On POSIX there are no privileges to set. |
251 return Open(pid); | 252 return Open(pid); |
252 } | 253 } |
253 | 254 |
254 // static | 255 // static |
255 Process Process::DeprecatedGetProcessFromHandle(ProcessHandle handle) { | 256 Process Process::DeprecatedGetProcessFromHandle(ProcessHandle handle) { |
256 DCHECK_NE(handle, GetCurrentProcessHandle()); | 257 DCHECK_NE(handle, GetCurrentProcessHandle()); |
257 return Process(handle); | 258 return Process(handle); |
258 } | 259 } |
259 | 260 |
260 #if !defined(OS_LINUX) && !defined(OS_MACOSX) | 261 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_AIX) |
261 // static | 262 // static |
262 bool Process::CanBackgroundProcesses() { | 263 bool Process::CanBackgroundProcesses() { |
263 return false; | 264 return false; |
264 } | 265 } |
265 #endif // !defined(OS_LINUX) && !defined(OS_MACOSX) | 266 #endif // !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_AIX) |
266 | 267 |
267 // static | 268 // static |
268 void Process::TerminateCurrentProcessImmediately(int exit_code) { | 269 void Process::TerminateCurrentProcessImmediately(int exit_code) { |
269 _exit(exit_code); | 270 _exit(exit_code); |
270 } | 271 } |
271 | 272 |
272 bool Process::IsValid() const { | 273 bool Process::IsValid() const { |
273 return process_ != kNullProcessHandle; | 274 return process_ != kNullProcessHandle; |
274 } | 275 } |
275 | 276 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 return WaitForExitWithTimeout(TimeDelta::Max(), exit_code); | 360 return WaitForExitWithTimeout(TimeDelta::Max(), exit_code); |
360 } | 361 } |
361 | 362 |
362 bool Process::WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) const { | 363 bool Process::WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) const { |
363 // Record the event that this thread is blocking upon (for hang diagnosis). | 364 // Record the event that this thread is blocking upon (for hang diagnosis). |
364 base::debug::ScopedProcessWaitActivity process_activity(this); | 365 base::debug::ScopedProcessWaitActivity process_activity(this); |
365 | 366 |
366 return WaitForExitWithTimeoutImpl(Handle(), exit_code, timeout); | 367 return WaitForExitWithTimeoutImpl(Handle(), exit_code, timeout); |
367 } | 368 } |
368 | 369 |
369 #if !defined(OS_LINUX) && !defined(OS_MACOSX) | 370 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_AIX) |
370 bool Process::IsProcessBackgrounded() const { | 371 bool Process::IsProcessBackgrounded() const { |
371 // See SetProcessBackgrounded(). | 372 // See SetProcessBackgrounded(). |
372 DCHECK(IsValid()); | 373 DCHECK(IsValid()); |
373 return false; | 374 return false; |
374 } | 375 } |
375 | 376 |
376 bool Process::SetProcessBackgrounded(bool value) { | 377 bool Process::SetProcessBackgrounded(bool value) { |
377 // Not implemented for POSIX systems other than Linux and Mac. With POSIX, if | 378 // Not implemented for POSIX systems other than Linux and Mac. With POSIX, if |
378 // we were to lower the process priority we wouldn't be able to raise it back | 379 // we were to lower the process priority we wouldn't be able to raise it back |
379 // to its initial priority. | 380 // to its initial priority. |
380 NOTIMPLEMENTED(); | 381 NOTIMPLEMENTED(); |
381 return false; | 382 return false; |
382 } | 383 } |
383 #endif // !defined(OS_LINUX) && !defined(OS_MACOSX) | 384 #endif // !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_AIX) |
384 | 385 |
385 int Process::GetPriority() const { | 386 int Process::GetPriority() const { |
386 DCHECK(IsValid()); | 387 DCHECK(IsValid()); |
387 return getpriority(PRIO_PROCESS, process_); | 388 return getpriority(PRIO_PROCESS, process_); |
388 } | 389 } |
389 | 390 |
390 } // namespace base | 391 } // namespace base |
OLD | NEW |