GNU CommonC++
process.h
Go to the documentation of this file.
1// Copyright (C) 1999-2005 Open Source Telecom Corporation.
2// Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
3//
4// This program is free software; you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation; either version 2 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 CCXX_PROCESS_H_
45#define CCXX_PROCESS_H_
46
47#ifndef CCXX_CONFIG_H_
48#include <cc++/config.h>
49#endif
50
51#ifndef CCXX_THREAD_H_
52#include <cc++/thread.h>
53#endif
54
55#ifdef CCXX_NAMESPACES
56namespace ost {
57#endif
58
70{
71private:
72 static bool rtflag;
73
74public:
75#ifndef WIN32
76 typedef RETSIGTYPE (*Trap)(int);
77
83 static void detach(void);
84
92 static void attach(const char *devname);
93
101 static Trap setPosixSignal(int signo, Trap handler);
102
110 static Trap setInterruptSignal(int signo, Trap handler);
111#endif
120 bool lock(bool future = true);
121
125 void unlock(void);
126
144 static int spawn(const char *exec, const char **argv, bool wait = true);
145
153 static int join(int pid);
154
162 static bool cancel(int pid, int sig = 0);
163
170 static const char *getEnv(const char *name);
171
179 static void setEnv(const char *name, const char *value, bool overwrite);
180
186 static const char *getConfigDir(void);
187
193 static const char *getHomeDir(void);
194
200 static const char *getUser(void);
201
207 static bool setUser(const char *id, bool grp = true);
208
214 static bool setGroup(const char *id);
215
221 static size_t getPageSize(void);
222
226 static void setPriority(int pri);
227
231 static void setScheduler(const char *policy);
232
236 static void setRealtime(int pri = 0);
237
241 static bool isScheduler(void);
242
246 static inline bool isRealtime(void)
247 {return rtflag;};
248};
249
260{
261private:
262#ifdef WIN32
263 HANDLE _mutex;
264 bool _flagged;
265#else
266 char *_path;
267#endif
268
269public:
275 Lockfile(const char *name);
276
281
286 {unlock();};
287
296 bool lock(const char *name);
297
301 void unlock(void);
302
308 bool isLocked(void);
309};
310
311#ifdef CCXX_NAMESPACES
312}
313#endif
314
315#endif
316
This class is used to create a "named" lock entity that can be used to control access to a resource b...
Definition process.h:260
bool lock(const char *name)
Lock a system-wide name for this process.
bool isLocked(void)
Flag if the current process has aqcuired a lock.
Lockfile(const char *name)
Create a lock under a known name.
Lockfile()
Create a new lock object that can be used to make locks.
~Lockfile()
Destroy the current lock and release it.
Definition process.h:285
void unlock(void)
Release an acquired lock.
A class for containing portable process related functions that help create portable code.
Definition process.h:70
static size_t getPageSize(void)
Return the effective operating system page size.
static const char * getConfigDir(void)
Get etc prefix path.
static bool setUser(const char *id, bool grp=true)
Set user id by name.
static void setRealtime(int pri=0)
Portable shortcut for setting realtime...
static const char * getUser(void)
Get user name.
void unlock(void)
Unlock process pages.
static const char * getEnv(const char *name)
Get system environment.
bool lock(bool future=true)
Lock a process in memory.
static void detach(void)
Detach current process into a daemon, posix only.
static const char * getHomeDir(void)
Get home directory.
static void setScheduler(const char *policy)
Used to set process scheduling policy.
static bool isRealtime(void)
Return true if realtime scheduling.
Definition process.h:246
static void attach(const char *devname)
Attach the current process to another device or i/o session.
static bool cancel(int pid, int sig=0)
Cancel a running child process.
static void setPriority(int pri)
Used to set process priority and optionally enable realtime.
static void setEnv(const char *name, const char *value, bool overwrite)
Set system environment in a standard manner.
static bool setGroup(const char *id)
Set the effective group id by name.
static int join(int pid)
Get the exit status of another process, waiting for it to exit.
static Trap setPosixSignal(int signo, Trap handler)
Set a posix compliant signal handler.
static Trap setInterruptSignal(int signo, Trap handler)
Set system call interuptable signal handler.
static int spawn(const char *exec, const char **argv, bool wait=true)
Spawn a process and wait for it's exit code.
static bool isScheduler(void)
Return true if scheduler settable.
#define __EXPORT
Definition config.h:1045
#define RETSIGTYPE
Definition config.h:706
Definition address.h:64
int HANDLE
Definition serial.h:60
Synchronization and threading services.