27 #ifndef NIDAS_UTIL_PROCESS_H
28 #define NIDAS_UTIL_PROCESS_H
39 #include <sys/types.h>
42 #include <nidas/Config.h>
44 #ifdef HAVE_SYS_CAPABILITY_H
45 #include <sys/capability.h>
48 #include <ext/stdio_filebuf.h>
50 namespace nidas {
namespace util {
126 const std::vector<std::string>& args,
127 const std::map<std::string, std::string>& env,
140 const std::vector<std::string>& args,
297 static bool getEnvVar(
const std::string& name,std::string& value);
299 static void setEnvVar(
const std::string& name,
const std::string& value);
342 mutable auto_ptr<__gnu_cxx::stdio_filebuf<char> >
_inbuf_ap;
354 mutable auto_ptr<__gnu_cxx::stdio_filebuf<char> >
_outbuf_ap;
366 mutable auto_ptr<__gnu_cxx::stdio_filebuf<char> >
_errbuf_ap;
std::istream & errStream()
Get the istream of the pipe that is connected to the standard error of the Process.
Definition: Process.h:228
int _outfd
File descriptor that is connected via a pipe to the standard out file descriptor of a spawned process...
Definition: Process.h:350
int getOutFd() const
Get the file descriptor of the pipe that is connected to the standard out of the Process.
Definition: Process.h:198
std::ostream & inStream()
Get the ostream of the pipe that is connected to the standard in of the Process.
Definition: Process.h:182
static bool getEffectiveCapability(int cap)
Check if this process has an effective capability.
Definition: Process.cc:533
void setErrFd(int val)
Definition: Process.cc:151
static std::string _pidFile
Definition: Process.h:323
pid_t getPid() const
The process id of the Process.
Definition: Process.h:241
Process provides an encapsulation of a spawned process, allowing the parent process to perform I/O wi...
Definition: Process.h:58
void closeOut()
Close the file descriptor and istream of the pipe connected to the standard out of the Process...
Definition: Process.cc:167
auto_ptr< std::istream > _errstream_ap
Definition: Process.h:368
static void addEffectiveCapability(int cap)
Add an effective capability to this process.
Definition: Process.cc:457
static unsigned long getMaxRSS()
Return the maximum resident set size of the current process, in bytes.
Definition: Process.cc:704
static void clearEnv()
Remove any environment settings made by setEnvVar and release any memory allocated to put those setti...
Definition: Process.cc:652
int wait(bool hang, int *status)
Do a system wait on a process.
Definition: Process.cc:364
static std::string expandEnvVars(std::string input)
Definition: Process.cc:567
Definition: Exception.h:35
auto_ptr< __gnu_cxx::stdio_filebuf< char > > _errbuf_ap
Definition: Process.h:366
auto_ptr< __gnu_cxx::stdio_filebuf< char > > _outbuf_ap
Definition: Process.h:354
int getInFd() const
Get the file descriptor of the pipe that is connected to the standard in of the Process.
Definition: Process.h:175
static pid_t checkPidFile(const std::string &pidFile)
Check if another process is running, using the named process id file.
Definition: Process.cc:386
int _infd
File descriptor that is connected via a pipe to the standard in file descriptor of a spawned process...
Definition: Process.h:334
static void clearEffectiveCapability(int cap)
Definition: Process.cc:496
int _errfd
File descriptor that is connected via a pipe to the standard error file descriptor of a spawned proce...
Definition: Process.h:362
static std::map< std::string, char * > _environment
Definition: Process.h:370
int getErrFd() const
Get the file descriptor of the pipe that is connected to the standard error of the Process...
Definition: Process.h:220
void setOutFd(int val)
Definition: Process.cc:143
pid_t _pid
Definition: Process.h:325
static Process spawn(const std::string &cmd, const std::vector< std::string > &args, const std::map< std::string, std::string > &env, int niceval=0)
Fork and execute a command and associated arguments and environment.
Definition: Process.cc:184
Definition: IOException.h:37
std::istream & outStream()
Get the istream of the pipe that is connected to the standard out of the Process. ...
Definition: Process.h:206
void kill(int signal)
Send a signal to the process.
Definition: Process.cc:352
auto_ptr< __gnu_cxx::stdio_filebuf< char > > _inbuf_ap
GNU extension filebuf which is needed to create a ostream from a file descriptor. ...
Definition: Process.h:342
static Mutex _envLock
Definition: Process.h:372
auto_ptr< std::istream > _outstream_ap
Definition: Process.h:356
~Process()
Destructor, which does very little.
Definition: Process.cc:131
static bool getEnvVar(const std::string &name, std::string &value)
Get an environment variable given a variable name like "HOST", without the '$', or any brackets...
Definition: Process.cc:623
static void removePidFile()
Remove the pid file.
Definition: Process.cc:450
Process()
Default constructor.
Definition: Process.cc:77
void closeIn()
Close the file descriptor and ostream of the pipe connected to the standard in of the Process...
Definition: Process.cc:159
static void setEnvVar(const std::string &name, const std::string &value)
Definition: Process.cc:632
void setInFd(int val)
Definition: Process.cc:135
void closeErr()
Close the file descriptor and istream of the pipe connected to the standard error of the Process...
Definition: Process.cc:175
auto_ptr< std::ostream > _instream_ap
Definition: Process.h:344
A C++ wrapper for a POSIX mutex.
Definition: ThreadSupport.h:154
static unsigned long getVMemSize()
Return the virtual memory size in bytes of the current process, as read from the /proc/pid/stat file...
Definition: Process.cc:681
Process & operator=(const Process &x)
Assignment operator.
Definition: Process.cc:105