1 | /* $Id: process.cpp 3672 2007-07-17 12:39:30Z 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 | * If you received this file as part of a commercial VirtualBox
|
---|
18 | * distribution, then only the terms of your commercial VirtualBox
|
---|
19 | * license agreement apply instead of the previous paragraph.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 |
|
---|
24 | /*******************************************************************************
|
---|
25 | * Header Files *
|
---|
26 | *******************************************************************************/
|
---|
27 | #include <iprt/process.h>
|
---|
28 | #include <iprt/assert.h>
|
---|
29 | #include <iprt/err.h>
|
---|
30 | #include "internal/process.h"
|
---|
31 | #include "internal/thread.h"
|
---|
32 |
|
---|
33 | #ifdef RT_OS_WINDOWS
|
---|
34 | # include <process.h>
|
---|
35 | #else
|
---|
36 | # include <unistd.h>
|
---|
37 | #endif
|
---|
38 |
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Get the identifier for the current process.
|
---|
42 | *
|
---|
43 | * @returns Process identifier.
|
---|
44 | */
|
---|
45 | RTDECL(RTPROCESS) RTProcSelf(void)
|
---|
46 | {
|
---|
47 | RTPROCESS Self = g_ProcessSelf;
|
---|
48 | if (Self != NIL_RTPROCESS)
|
---|
49 | return Self;
|
---|
50 |
|
---|
51 | /* lazy init. */
|
---|
52 | #ifdef _MSC_VER
|
---|
53 | Self = _getpid(); /* crappy ansi compiler */
|
---|
54 | #else
|
---|
55 | Self = getpid();
|
---|
56 | #endif
|
---|
57 | g_ProcessSelf = Self;
|
---|
58 | return Self;
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Attempts to alter the priority of the current process.
|
---|
64 | *
|
---|
65 | * @returns iprt status code.
|
---|
66 | * @param enmPriority The new priority.
|
---|
67 | */
|
---|
68 | RTR3DECL(int) RTProcSetPriority(RTPROCPRIORITY enmPriority)
|
---|
69 | {
|
---|
70 | if (enmPriority > RTPROCPRIORITY_INVALID && enmPriority < RTPROCPRIORITY_LAST)
|
---|
71 | return rtThreadDoSetProcPriority(enmPriority);
|
---|
72 | AssertMsgFailed(("enmPriority=%d\n", enmPriority));
|
---|
73 | return VERR_INVALID_PARAMETER;
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Gets the current priority of this process.
|
---|
79 | *
|
---|
80 | * @returns The priority (see RTPROCPRIORITY).
|
---|
81 | */
|
---|
82 | RTR3DECL(RTPROCPRIORITY) RTProcGetPriority(void)
|
---|
83 | {
|
---|
84 | return g_enmProcessPriority;
|
---|
85 | }
|
---|
86 |
|
---|