Rudiments
process.h
1 // Copyright (c) 1999-2013 David Muse
2 // See the COPYING file for more information.
3 
4 #ifndef RUDIMENTS_PROCESS_H
5 #define RUDIMENTS_PROCESS_H
6 
7 #include <rudiments/private/processincludes.h>
8 
9 // wrap:
10 // unistd.h - nice()
11 // getgroups()
12 // vfork()
13 // profil()
14 // acct()
15 // getdtablesize()
16 // brk()/sbrk()
17 // syscall()
18 // sched.h - functions for manipulating the scheduler
19 // sched_setparam(),sched_getparam()
20 // sched_setscheduler(),sched_getscheduler()
21 // sched_yield(),
22 // sched_get_priority_max(),sched_get_priority_min()
23 // sched_rr_get_interval()
24 // sched_setaffinity(),sched_getaffinity()
25 // sys/acct.h - acct() - process accounting on/off
26 // sys/ptrace.h - ptrace()
27 // sys/resource.h - get/set process priority/resource usage
28 // getrlimit(),setrlimit()
29 // getrusage()
30 // getpriority(),setpriority()
31 // sys/times.h - times() - function for getting process times
32 // not in many systems -
33 // unistd.h - group_member()
34 // getresuid(),getresgid()
35 // setresuid(),setresgid()
36 // sys/gmon.h and sys/gmon_out.h - monstartup()
37 // linux only -
38 // execinfo.h - backtrace(),backtrace_symbols(),
39 // backtrace_symbols_fd()
40 // sys/prctl.h - prctl()
41 // not in bsd -
42 // ucontext.h - user-level context switching
43 // getcontext(),setcontext(),swapcontext(),makecontext()
44 
47 class RUDIMENTS_DLLSPEC process {
48  public:
49 
51  static pid_t getProcessId();
52 
55  static pid_t getParentProcessId();
56 
59  static pid_t getProcessGroupId();
60 
63  static pid_t getProcessGroupId(pid_t pid);
64 
67  static bool setProcessGroupId();
68 
70  static bool setProcessGroupId(pid_t pgid);
71 
73  static bool setProcessGroupId(pid_t pid, pid_t pgid);
74 
76  static pid_t getSessionId();
77 
79  static pid_t getSessionId(pid_t pid);
80 
85  static pid_t newSession();
86 
88  static uid_t getRealUserId();
89 
91  static uid_t getEffectiveUserId();
92 
98  static bool setUserId(uid_t uid);
99 
105  static bool setUser(const char *username);
106 
111  static bool setEffectiveUserId(uid_t uid);
112 
120  static bool setRealAndEffectiveUserId(uid_t uid,
121  uid_t euid);
122 
124  static gid_t getRealGroupId();
125 
127  static gid_t getEffectiveGroupId();
128 
134  static bool setGroupId(gid_t gid);
135 
141  static bool setGroup(const char *groupname);
142 
147  static bool setEffectiveGroupId(gid_t gid);
148 
156  static bool setRealAndEffectiveGroupId(gid_t gid,
157  gid_t egid);
158 
161  static mode_t setFileCreationMask(mode_t mask);
162 
170  static pid_t fork();
171 
180  static bool exec(const char *command,
181  const char * const *args);
182 
191  static pid_t spawn(const char *command,
192  const char * const *args);
193 
199  static bool detach();
200 
203  static void exit(int32_t status);
204 
208  static void exitImmediately(int32_t status);
209 
212  static void exitOnCrashOrShutDown();
213 
217  static int64_t checkForPidFile(const char *filename);
218 
226  static bool createPidFile(const char *filename,
227  mode_t permissions);
228 
233  static void exitOnShutDown();
234 
237  static void handleShutDown(
238  void (*shutdownfunction)(int32_t));
239 
245  static void exitOnCrash();
246 
250  static void handleCrash(void (*crashfunction)(int32_t));
251 
255  static void waitForChildren();
256 
263  static void dontWaitForChildren();
264 
265  #include <rudiments/private/process.h>
266 };
267 
268 #endif