1 | /** @file
|
---|
2 | * innotek Portable Runtime - Process Management.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License as published by the Free Software Foundation,
|
---|
12 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
13 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
14 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef ___iprt_process_h
|
---|
18 | #define ___iprt_process_h
|
---|
19 |
|
---|
20 | #include <iprt/cdefs.h>
|
---|
21 | #include <iprt/types.h>
|
---|
22 |
|
---|
23 | __BEGIN_DECLS
|
---|
24 |
|
---|
25 | /** @defgroup grp_rt_process RTProc - Process Management
|
---|
26 | * @ingroup grp_rt
|
---|
27 | * @{
|
---|
28 | */
|
---|
29 |
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Process priority.
|
---|
33 | *
|
---|
34 | * The process priority is used to select how scheduling properties
|
---|
35 | * are assigned to the different thread types (see THREADTYPE).
|
---|
36 | *
|
---|
37 | * In addition to using the policy assigned to the process at startup (DEFAULT)
|
---|
38 | * it is possible to change the process priority at runtime. This allows for
|
---|
39 | * a GUI, resource manager or admin to adjust the general priorty of a task
|
---|
40 | * without upsetting the fine-tuned priority of the threads within.
|
---|
41 | */
|
---|
42 | typedef enum RTPROCPRIORITY
|
---|
43 | {
|
---|
44 | /** Invalid priority. */
|
---|
45 | RTPROCPRIORITY_INVALID = 0,
|
---|
46 | /** Default priority.
|
---|
47 | * Derive the schedulding policy from the priority of the RTR3Init()
|
---|
48 | * and RTProcSetPriority() callers and the rights the process have
|
---|
49 | * to alter its own priority.
|
---|
50 | */
|
---|
51 | RTPROCPRIORITY_DEFAULT,
|
---|
52 | /** Flat priority.
|
---|
53 | * Assumes a scheduling policy which puts the process at the default priority
|
---|
54 | * and with all thread at the same priority.
|
---|
55 | */
|
---|
56 | RTPROCPRIORITY_FLAT,
|
---|
57 | /** Low priority.
|
---|
58 | * Assumes a scheduling policy which puts the process mostly below the
|
---|
59 | * default priority of the host OS.
|
---|
60 | */
|
---|
61 | RTPROCPRIORITY_LOW,
|
---|
62 | /** Normal priority.
|
---|
63 | * Assume a scheduling policy which shares the cpu resources fairly with
|
---|
64 | * other processes running with the default priority of the host OS.
|
---|
65 | */
|
---|
66 | RTPROCPRIORITY_NORMAL,
|
---|
67 | /** High priority.
|
---|
68 | * Assumes a scheduling policy which puts the task above the default
|
---|
69 | * priority of the host OS. This policy might easily cause other tasks
|
---|
70 | * in the system to starve.
|
---|
71 | */
|
---|
72 | RTPROCPRIORITY_HIGH,
|
---|
73 | /** Last priority, used for validation. */
|
---|
74 | RTPROCPRIORITY_LAST
|
---|
75 | } RTPROCPRIORITY;
|
---|
76 |
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Get the current process identifier.
|
---|
80 | *
|
---|
81 | * @returns Process identifier.
|
---|
82 | */
|
---|
83 | RTDECL(RTPROCESS) RTProcSelf(void);
|
---|
84 |
|
---|
85 |
|
---|
86 | #ifdef IN_RING0
|
---|
87 | /**
|
---|
88 | * Get the current process handle.
|
---|
89 | *
|
---|
90 | * @returns Ring-0 process handle.
|
---|
91 | */
|
---|
92 | RTR0DECL(RTR0PROCESS) RTR0ProcHandleSelf(void);
|
---|
93 | #endif
|
---|
94 |
|
---|
95 |
|
---|
96 | #ifdef IN_RING3
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Attempts to alter the priority of the current process.
|
---|
100 | *
|
---|
101 | * @returns iprt status code.
|
---|
102 | * @param enmPriority The new priority.
|
---|
103 | */
|
---|
104 | RTR3DECL(int) RTProcSetPriority(RTPROCPRIORITY enmPriority);
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Gets the current priority of this process.
|
---|
108 | *
|
---|
109 | * @returns The priority (see RTPROCPRIORITY).
|
---|
110 | */
|
---|
111 | RTR3DECL(RTPROCPRIORITY) RTProcGetPriority(void);
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Create a child process.
|
---|
115 | *
|
---|
116 | * @returns iprt status code.
|
---|
117 | * @param pszExec Executable image to use to create the child process.
|
---|
118 | * @param papszArgs Pointer to an array of arguments to the child. The array terminated by an entry containing NULL.
|
---|
119 | * @param papszEnv Pointer to array of environment variables for the child process. An NULL entry
|
---|
120 | * terminates the array. The variables are on the form '\<var\>=\<value\>'.
|
---|
121 | * If NULL the environment of the process will be used.
|
---|
122 | * @param fFlags Flags. This is currently reserved and must be 0.
|
---|
123 | * @param pProcess Where to store the process identifier on successful return.
|
---|
124 | * The content is not changed on failure. NULL is allowed.
|
---|
125 | */
|
---|
126 | RTR3DECL(int) RTProcCreate(const char *pszExec, const char * const *papszArgs, const char * const *papszEnv, unsigned fFlags, PRTPROCESS pProcess);
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * Process exit reason.
|
---|
130 | */
|
---|
131 | typedef enum RTPROCEXITREASON
|
---|
132 | {
|
---|
133 | /** Normal exit. iStatus contains the exit code. */
|
---|
134 | RTPROCEXITREASON_NORMAL = 1,
|
---|
135 | /** Any abnormal exit. iStatus is undefined. */
|
---|
136 | RTPROCEXITREASON_ABEND,
|
---|
137 | /** Killed by a signal. The iStatus field contains the signal number. */
|
---|
138 | RTPROCEXITREASON_SIGNAL
|
---|
139 | } RTPROCEXITREASON;
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Process exit status.
|
---|
143 | */
|
---|
144 | typedef struct RTPROCSTATUS
|
---|
145 | {
|
---|
146 | /** The process exit status if the exit was a normal one. */
|
---|
147 | int iStatus;
|
---|
148 | /** The reason the process terminated. */
|
---|
149 | RTPROCEXITREASON enmReason;
|
---|
150 | } RTPROCSTATUS;
|
---|
151 | /** Pointer to a process exit status structure. */
|
---|
152 | typedef RTPROCSTATUS *PRTPROCSTATUS;
|
---|
153 | /** Pointer to a const process exit status structure. */
|
---|
154 | typedef const RTPROCSTATUS *PCRTPROCSTATUS;
|
---|
155 |
|
---|
156 |
|
---|
157 | /** Flags for RTProcWait().
|
---|
158 | * @{ */
|
---|
159 | /** Block indefinitly waiting for the process to exit. */
|
---|
160 | #define RTPROCWAIT_FLAGS_BLOCK 0
|
---|
161 | /** Don't block, just check if the process have exitted. */
|
---|
162 | #define RTPROCWAIT_FLAGS_NOBLOCK 1
|
---|
163 | /** @} */
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Waits for a process, resumes on interruption.
|
---|
167 | *
|
---|
168 | * @returns VINF_SUCCESS when the status code for the process was collected and put in *pProcStatus.
|
---|
169 | * @returns VERR_PROCESS_NOT_FOUND if the specified process wasn't found.
|
---|
170 | * @returns VERR_PROCESS_RUNNING when the RTPROCWAIT_FLAG_NOBLOCK and the process haven't exitted yet.
|
---|
171 | *
|
---|
172 | * @param Process The process to wait for.
|
---|
173 | * @param fFlags The wait flags, any of the RTPROCWAIT_FLAGS_ \#defines.
|
---|
174 | * @param pProcStatus Where to store the exit status on success.
|
---|
175 | */
|
---|
176 | RTR3DECL(int) RTProcWait(RTPROCESS Process, unsigned fFlags, PRTPROCSTATUS pProcStatus);
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * Waits for a process, returns on interruption.
|
---|
180 | *
|
---|
181 | * @returns VINF_SUCCESS when the status code for the process was collected and put in *pProcStatus.
|
---|
182 | * @returns VERR_PROCESS_NOT_FOUND if the specified process wasn't found.
|
---|
183 | * @returns VERR_PROCESS_RUNNING when the RTPROCWAIT_FLAG_NOBLOCK and the process haven't exitted yet.
|
---|
184 | * @returns VERR_INTERRUPTED when the wait was interrupted by the arrival of a signal or other async event.
|
---|
185 | *
|
---|
186 | * @param Process The process to wait for.
|
---|
187 | * @param fFlags The wait flags, any of the RTPROCWAIT_FLAGS_ \#defines.
|
---|
188 | * @param pProcStatus Where to store the exit status on success.
|
---|
189 | */
|
---|
190 | RTR3DECL(int) RTProcWaitNoResume(RTPROCESS Process, unsigned fFlags, PRTPROCSTATUS pProcStatus);
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * Terminates (kills) a running process.
|
---|
194 | *
|
---|
195 | * @returns IPRT status code.
|
---|
196 | * @param Process The process to terminate.
|
---|
197 | */
|
---|
198 | RTR3DECL(int) RTProcTerminate(RTPROCESS Process);
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Gets the processor affinity mask of the current process.
|
---|
202 | *
|
---|
203 | * @returns The affinity mask.
|
---|
204 | */
|
---|
205 | RTR3DECL(uint64_t) RTProcGetAffinityMask(void);
|
---|
206 |
|
---|
207 | /**
|
---|
208 | * Gets the executable image name of the current process.
|
---|
209 | *
|
---|
210 | *
|
---|
211 | * @returns pszExecName on success. NULL on buffer overflow or other errors.
|
---|
212 | *
|
---|
213 | * @param pszExecName Where to store the name.
|
---|
214 | * @param cchExecName The size of the buffer.
|
---|
215 | */
|
---|
216 | RTR3DECL(char *) RTProcGetExecutableName(char *pszExecName, size_t cchExecName);
|
---|
217 |
|
---|
218 | #endif /* IN_RING3 */
|
---|
219 |
|
---|
220 | /** @} */
|
---|
221 |
|
---|
222 | __END_DECLS
|
---|
223 |
|
---|
224 | #endif
|
---|
225 |
|
---|