1 | /* $Id: process.cpp 4071 2007-08-07 17:07:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * innotek Portable Runtime - Process, Common.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 |
|
---|
20 | /*******************************************************************************
|
---|
21 | * Header Files *
|
---|
22 | *******************************************************************************/
|
---|
23 | #include <iprt/process.h>
|
---|
24 | #include <iprt/assert.h>
|
---|
25 | #include <iprt/err.h>
|
---|
26 | #include "internal/process.h"
|
---|
27 | #include "internal/thread.h"
|
---|
28 |
|
---|
29 | #ifdef RT_OS_WINDOWS
|
---|
30 | # include <process.h>
|
---|
31 | #else
|
---|
32 | # include <unistd.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Get the identifier for the current process.
|
---|
38 | *
|
---|
39 | * @returns Process identifier.
|
---|
40 | */
|
---|
41 | RTDECL(RTPROCESS) RTProcSelf(void)
|
---|
42 | {
|
---|
43 | RTPROCESS Self = g_ProcessSelf;
|
---|
44 | if (Self != NIL_RTPROCESS)
|
---|
45 | return Self;
|
---|
46 |
|
---|
47 | /* lazy init. */
|
---|
48 | #ifdef _MSC_VER
|
---|
49 | Self = _getpid(); /* crappy ansi compiler */
|
---|
50 | #else
|
---|
51 | Self = getpid();
|
---|
52 | #endif
|
---|
53 | g_ProcessSelf = Self;
|
---|
54 | return Self;
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Attempts to alter the priority of the current process.
|
---|
60 | *
|
---|
61 | * @returns iprt status code.
|
---|
62 | * @param enmPriority The new priority.
|
---|
63 | */
|
---|
64 | RTR3DECL(int) RTProcSetPriority(RTPROCPRIORITY enmPriority)
|
---|
65 | {
|
---|
66 | if (enmPriority > RTPROCPRIORITY_INVALID && enmPriority < RTPROCPRIORITY_LAST)
|
---|
67 | return rtThreadDoSetProcPriority(enmPriority);
|
---|
68 | AssertMsgFailed(("enmPriority=%d\n", enmPriority));
|
---|
69 | return VERR_INVALID_PARAMETER;
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Gets the current priority of this process.
|
---|
75 | *
|
---|
76 | * @returns The priority (see RTPROCPRIORITY).
|
---|
77 | */
|
---|
78 | RTR3DECL(RTPROCPRIORITY) RTProcGetPriority(void)
|
---|
79 | {
|
---|
80 | return g_enmProcessPriority;
|
---|
81 | }
|
---|
82 |
|
---|