VirtualBox

source: vbox/trunk/include/iprt/process.h@ 204

Last change on this file since 204 was 204, checked in by vboxsync, 18 years ago

runtime.h now includes everything. Created a new header, initterm.h, which includes the RT*Init/Term() prototypes.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette