GNU CommonC++
process.h
Go to the documentation of this file.
1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // Common C++. If you copy code from other releases into a copy of GNU
28 // Common C++, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU Common C++, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37 
43 #ifndef CCXX_PROCESS_H_
44 #define CCXX_PROCESS_H_
45 
46 #ifndef CCXX_CONFIG_H_
47 #include <cc++/config.h>
48 #endif
49 
50 #ifndef CCXX_THREAD_H_
51 #include <cc++/thread.h>
52 #endif
53 
54 #ifdef CCXX_NAMESPACES
55 namespace ost {
56 #endif
57 
69 {
70 private:
71  static bool rtflag;
72 
73 public:
74 #ifndef WIN32
75  typedef RETSIGTYPE (*Trap)(int);
76 
82  static void detach(void);
83 
91  static void attach(const char *devname);
92 
100  static Trap setPosixSignal(int signo, Trap handler);
101 
109  static Trap setInterruptSignal(int signo, Trap handler);
110 #endif
111 
119  bool lock(bool future = true);
120 
124  void unlock(void);
125 
143  static int spawn(const char *exec, const char **argv, bool wait = true);
144 
152  static int join(int pid);
153 
161  static bool cancel(int pid, int sig = 0);
162 
169  static const char *getEnv(const char *name);
170 
178  static void setEnv(const char *name, const char *value, bool overwrite);
179 
185  static const char *getConfigDir(void);
186 
192  static const char *getHomeDir(void);
193 
199  static const char *getUser(void);
200 
206  static bool setUser(const char *id, bool grp = true);
207 
213  static bool setGroup(const char *id);
214 
220  static size_t getPageSize(void);
221 
225  static void setPriority(int pri);
226 
230  static void setScheduler(const char *policy);
231 
235  static void setRealtime(int pri = 0);
236 
240  static bool isScheduler(void);
241 
245  static inline bool isRealtime(void)
246  {return rtflag;};
247 };
248 
259 {
260 private:
261 #ifdef WIN32
262  HANDLE _mutex;
263  bool _flagged;
264 #else
265  char *_path;
266 #endif
267 
268 public:
274  Lockfile(const char *name);
275 
279  Lockfile();
280 
285  {unlock();};
286 
295  bool lock(const char *name);
296 
300  void unlock(void);
301 
307  bool isLocked(void);
308 };
309 
310 #ifdef CCXX_NAMESPACES
311 }
312 #endif
313 
314 #endif
315