VirtualBox

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

Last change on this file since 4672 was 4475, checked in by vboxsync, 17 years ago

Some adjustments to RTEnv and RTProcCreate. Should work on darwin now.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
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 */
42typedef 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 */
83RTDECL(RTPROCESS) RTProcSelf(void);
84
85
86#ifdef IN_RING0
87/**
88 * Get the current process handle.
89 *
90 * @returns Ring-0 process handle.
91 */
92RTR0DECL(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 */
104RTR3DECL(int) RTProcSetPriority(RTPROCPRIORITY enmPriority);
105
106/**
107 * Gets the current priority of this process.
108 *
109 * @returns The priority (see RTPROCPRIORITY).
110 */
111RTR3DECL(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 Env Handle to the environment block for the child.
120 * @param fFlags Flags. This is currently reserved and must be 0.
121 * @param pProcess Where to store the process identifier on successful return.
122 * The content is not changed on failure. NULL is allowed.
123 */
124RTR3DECL(int) RTProcCreate(const char *pszExec, const char * const *papszArgs, RTENV Env, unsigned fFlags, PRTPROCESS pProcess);
125
126/**
127 * Process exit reason.
128 */
129typedef enum RTPROCEXITREASON
130{
131 /** Normal exit. iStatus contains the exit code. */
132 RTPROCEXITREASON_NORMAL = 1,
133 /** Any abnormal exit. iStatus is undefined. */
134 RTPROCEXITREASON_ABEND,
135 /** Killed by a signal. The iStatus field contains the signal number. */
136 RTPROCEXITREASON_SIGNAL
137} RTPROCEXITREASON;
138
139/**
140 * Process exit status.
141 */
142typedef struct RTPROCSTATUS
143{
144 /** The process exit status if the exit was a normal one. */
145 int iStatus;
146 /** The reason the process terminated. */
147 RTPROCEXITREASON enmReason;
148} RTPROCSTATUS;
149/** Pointer to a process exit status structure. */
150typedef RTPROCSTATUS *PRTPROCSTATUS;
151/** Pointer to a const process exit status structure. */
152typedef const RTPROCSTATUS *PCRTPROCSTATUS;
153
154
155/** Flags for RTProcWait().
156 * @{ */
157/** Block indefinitly waiting for the process to exit. */
158#define RTPROCWAIT_FLAGS_BLOCK 0
159/** Don't block, just check if the process have exitted. */
160#define RTPROCWAIT_FLAGS_NOBLOCK 1
161/** @} */
162
163/**
164 * Waits for a process, resumes on interruption.
165 *
166 * @returns VINF_SUCCESS when the status code for the process was collected and put in *pProcStatus.
167 * @returns VERR_PROCESS_NOT_FOUND if the specified process wasn't found.
168 * @returns VERR_PROCESS_RUNNING when the RTPROCWAIT_FLAG_NOBLOCK and the process haven't exitted yet.
169 *
170 * @param Process The process to wait for.
171 * @param fFlags The wait flags, any of the RTPROCWAIT_FLAGS_ \#defines.
172 * @param pProcStatus Where to store the exit status on success.
173 */
174RTR3DECL(int) RTProcWait(RTPROCESS Process, unsigned fFlags, PRTPROCSTATUS pProcStatus);
175
176/**
177 * Waits for a process, returns on interruption.
178 *
179 * @returns VINF_SUCCESS when the status code for the process was collected and put in *pProcStatus.
180 * @returns VERR_PROCESS_NOT_FOUND if the specified process wasn't found.
181 * @returns VERR_PROCESS_RUNNING when the RTPROCWAIT_FLAG_NOBLOCK and the process haven't exitted yet.
182 * @returns VERR_INTERRUPTED when the wait was interrupted by the arrival of a signal or other async event.
183 *
184 * @param Process The process to wait for.
185 * @param fFlags The wait flags, any of the RTPROCWAIT_FLAGS_ \#defines.
186 * @param pProcStatus Where to store the exit status on success.
187 */
188RTR3DECL(int) RTProcWaitNoResume(RTPROCESS Process, unsigned fFlags, PRTPROCSTATUS pProcStatus);
189
190/**
191 * Terminates (kills) a running process.
192 *
193 * @returns IPRT status code.
194 * @param Process The process to terminate.
195 */
196RTR3DECL(int) RTProcTerminate(RTPROCESS Process);
197
198/**
199 * Gets the processor affinity mask of the current process.
200 *
201 * @returns The affinity mask.
202 */
203RTR3DECL(uint64_t) RTProcGetAffinityMask(void);
204
205/**
206 * Gets the executable image name of the current process.
207 *
208 *
209 * @returns pszExecName on success. NULL on buffer overflow or other errors.
210 *
211 * @param pszExecName Where to store the name.
212 * @param cchExecName The size of the buffer.
213 */
214RTR3DECL(char *) RTProcGetExecutableName(char *pszExecName, size_t cchExecName);
215
216#endif /* IN_RING3 */
217
218/** @} */
219
220__END_DECLS
221
222#endif
223
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