CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
process.h
Go to the documentation of this file.
1#pragma once
2
5
9
10#include <cx/closure/closure.h>
12#include <cx/container/sarray.h>
13#include <cx/cx.h>
14#include <cx/sys/processobj.h>
15
16CX_C_BEGIN
17
126
128typedef int64 ProcessID;
129
131#define PROCESS_InvalidID ((ProcessID)-1)
132
137#define PROC_ExitCodeUnknown ((int32)-1)
138
149
152#define SType_ProcessInfo ProcessInfo*
153#define STStorageType_ProcessInfo ProcessInfo
154#define STypeArg_ProcessInfo(type, val) stgeneric(opaque, &(val))
155#define STypeArgPtr_ProcessInfo(type, val) &stgeneric(opaque, (val))
156#define STypeCheckedArg_ProcessInfo(type, val) stType(type), stArg(type, val)
157#define STypeCheckedPtrArg_ProcessInfo(type, val) stType(type), stArgPtr(type, val)
158
166
176void procInfoInit(_Out_ ProcessInfo* info);
177
186void procInfoDestroy(_Inout_ ProcessInfo* info);
187
199void procInfoCopy(_Inout_ ProcessInfo* dest, _In_ const ProcessInfo* src);
200
217bool procEnum(_Inout_ sa_ProcessInfo* out, flags_t flags);
218
238bool procFind(_Inout_ sa_ProcessInfo* out, _In_ strref name, flags_t flags);
239
256bool procGetInfoByID(_Inout_ ProcessInfo* out, ProcessID pid, flags_t flags);
257
272bool procGetInfo(_Inout_ ProcessInfo* out, _In_ Process* proc, flags_t flags);
273
283
297
302
305
308
315};
316
324typedef struct ProcessOpts {
325 string workdir;
327 string stdioPath;
328 hashtable env;
329 sa_string envUnset;
330 flags_t flags;
332
342void procOptsInit(_Out_ ProcessOpts* opts);
343
352void procOptsDestroy(_Inout_ ProcessOpts* opts);
353
364void procOptsSetEnv(_Inout_ ProcessOpts* opts, _In_ strref name, _In_opt_ strref val);
365
378void procOptsUnsetEnv(_Inout_ ProcessOpts* opts, _In_ strref name);
379
402_Ret_opt_valid_ Process* procLaunch(_In_ strref exe, sa_string args, _In_opt_ ProcessOpts* opts);
403
415_Ret_opt_valid_ Process* procOpen(ProcessID pid);
416
430#define procRelease(pproc) objRelease(pproc)
431
442
454bool procRunning(_In_ Process* proc);
455
469bool procWait(_In_ Process* proc, int64 timeout);
470
489bool procExitCode(_In_ Process* proc, _Out_ int32* code);
490
507bool procTerminate(_In_ Process* proc, bool force);
508
536bool procNotifyExit(_In_ Process* proc, _In_ closure cls);
537
553void procNotifyCancel(_In_ Process* proc);
554
567bool procName(_In_ Process* proc, _Inout_ string* out);
568
586bool procExePath(_In_ Process* proc, _Inout_ string* out);
587
588CX_C_END
589
Basic closure functionality.
#define saDeclare(name)
Definition sarray.h:93
#define stDeclare(name)
Definition stype.h:1908
bool procGetInfo(ProcessInfo *out, Process *proc, flags_t flags)
bool procTerminate(Process *proc, bool force)
void procNotifyCancel(Process *proc)
bool procEnum(sa_ProcessInfo *out, flags_t flags)
void procOptsUnsetEnv(ProcessOpts *opts, strref name)
bool procWait(Process *proc, int64 timeout)
Process * procLaunch(strref exe, sa_string args, ProcessOpts *opts)
void procOptsSetEnv(ProcessOpts *opts, strref name, strref val)
void procOptsInit(ProcessOpts *opts)
void procInfoCopy(ProcessInfo *dest, const ProcessInfo *src)
void procInfoDestroy(ProcessInfo *info)
bool procExePath(Process *proc, string *out)
ProcessID procCurrentID(void)
bool procNotifyExit(Process *proc, closure cls)
void procOptsDestroy(ProcessOpts *opts)
ProcLaunchFlags
Flags for procLaunch()
Definition process.h:299
bool procRunning(Process *proc)
bool procName(Process *proc, string *out)
bool procExitCode(Process *proc, int32 *code)
Process * procOpen(ProcessID pid)
bool procFind(sa_ProcessInfo *out, strref name, flags_t flags)
enum ProcStdioEnum ProcStdio
Where a launched process's standard input, output and error go.
bool procGetInfoByID(ProcessInfo *out, ProcessID pid, flags_t flags)
int64 ProcessID
Operating system process id.
Definition process.h:128
ProcEnumFlags
Flags for procEnum() and procFind()
Definition process.h:160
ProcessID procID(Process *proc)
ProcStdioEnum
Where a launched process's standard input, output and error go.
Definition process.h:285
void procInfoInit(ProcessInfo *info)
@ PROC_Detached
Put the child in its own session so it outlives the caller.
Definition process.h:301
@ PROC_NewGroup
Give the child its own process group, so it can be signalled as a group.
Definition process.h:304
@ PROC_NewConsole
Windows: give the child its own console window. Ignored elsewhere.
Definition process.h:314
@ PROC_NoWindow
Windows: do not give the child a console window. Ignored elsewhere.
Definition process.h:307
@ PROC_EnumFullPath
Also resolve each process's full executable path.
Definition process.h:164
@ PROC_StdioNull
The child's stdio is discarded (/dev/null, or NUL on Windows)
Definition process.h:287
@ PROC_StdioInherit
The child shares the caller's stdin, stdout and stderr.
Definition process.h:286
@ PROC_StdioFile
The child's stdout and stderr both go to ProcessOpts::stdioPath.
Definition process.h:295
Hash table container with type-safe generic key-value storage.
Dynamic arrays with type-safe generic programming.
ProcessID pid
Process id; always present.
Definition process.h:144
ProcessID ppid
Parent process id, or PROCESS_InvalidID if it could not be read.
Definition process.h:145
string name
Process name; always present.
Definition process.h:146
string exepath
Full path to the executable, or empty if it could not be read.
Definition process.h:147
string workdir
Directory to start the child in; empty inherits the caller's.
Definition process.h:325
flags_t flags
ProcLaunchFlags.
Definition process.h:330
hashtable env
Variables to set in the child, name to value.
Definition process.h:328
sa_string envUnset
Variables to remove from the child.
Definition process.h:329
ProcStdio stdio
What to do with the child's stdin, stdout and stderr.
Definition process.h:326
string stdioPath
File for PROC_StdioFile; required in that mode, ignored otherwise.
Definition process.h:327