UCommon
process.h
Go to the documentation of this file.
1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
3 // Copyright (C) 2015 Cherokees of Idaho.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free software
19 // library without restriction. Specifically, if other files instantiate
20 // templates or use macros or inline functions from this file, or you compile
21 // this file and link it with other files to produce an executable, this
22 // file does not by itself cause the resulting executable to be covered by
23 // the GNU General Public License. This exception does not however
24 // invalidate any other reasons why the executable file might be covered by
25 // the GNU General Public License.
26 //
27 // This exception applies only to the code released under the name GNU
28 // Common C++. If you copy code from other releases into a copy of GNU
29 // Common C++, as the General Public License permits, the exception does
30 // not apply to the code that you add in this way. To avoid misleading
31 // anyone as to the status of such modified files, you must delete
32 // this exception notice from them.
33 //
34 // If you write modifications of your own for GNU Common C++, it is your choice
35 // whether to permit this exception to apply to your modifications.
36 // If you do not wish that, delete this exception notice.
37 //
38 
44 #ifndef COMMONCPP_PROCESS_H_
45 #define COMMONCPP_PROCESS_H_
46 
47 #ifndef COMMONCPP_CONFIG_H_
48 #include <commoncpp/config.h>
49 #endif
50 
51 #ifndef COMMONCPP_THREAD_H_
52 #include <commoncpp/thread.h>
53 #endif
54 
55 namespace ost {
56 
67 class __EXPORT Process
68 {
69 private:
70  static bool rtflag;
71 
72 public:
73 #ifndef _MSWINDOWS_
74  typedef void (*Trap)(int);
75 
81  static void detach(void);
82 
90  static void attach(const char *devname);
91 
99  static Trap setPosixSignal(int signo, Trap handler);
100 
108  static Trap setInterruptSignal(int signo, Trap handler);
109 #endif
110 
118  bool lock(bool future = true);
119 
123  void unlock(void);
124 
142  static int spawn(const char *exec, const char **argv, bool wait = true);
143 
151  static int join(int pid);
152 
160  static bool cancel(int pid, int sig = 0);
161 
168  static const char *getEnv(const char *name);
169 
177  static void setEnv(const char *name, const char *value, bool overwrite);
178 
184  static const char *getConfigDir(void);
185 
191  static const char *getHomeDir(void);
192 
198  static const char *getUser(void);
199 
205  static bool setUser(const char *id, bool grp = true);
206 
212  static bool setGroup(const char *id);
213 
219  static size_t getPageSize(void);
220 
224  static void setPriority(int pri);
225 
229  static void setScheduler(const char *policy);
230 
234  static void setRealtime(int pri = 0);
235 
239  static bool isScheduler(void);
240 
244  static inline bool isRealtime(void)
245  {return rtflag;}
246 };
247 
257 class __EXPORT Lockfile
258 {
259 private:
260 #ifdef _MSWINDOWS_
261  HANDLE _mutex;
262  bool _flagged;
263 #else
264  char *_path;
265 #endif
266 
267 public:
273  Lockfile(const char *name);
274 
278  Lockfile();
279 
284  {unlock();}
285 
294  bool lock(const char *name);
295 
299  void unlock(void);
300 
306  bool isLocked(void);
307 };
308 
309 } // namespace ost
310 
311 #endif
Definition: address.h:59
A class for containing portable process related functions that help create portable code...
Definition: process.h:67
This class is used to create a "named" lock entity that can be used to control access to a resource b...
Definition: process.h:257
static bool isRealtime(void)
Return true if realtime scheduling.
Definition: process.h:244
~Lockfile()
Destroy the current lock and release it.
Definition: process.h:283
void lock(ExclusiveAccess &object)
Convenience function to exclusively lock an object through it's protocol.
Definition: access.h:253
void unlock(ExclusiveAccess &object)
Convenience function to unlock an exclusive object through it's protocol.
Definition: access.h:262
void wait(barrier_t &barrier)
Convenience function to wait on a barrier.
Definition: thread.h:1921
Common C++ thread class and sychronization objects.