27#ifndef NIDAS_UTIL_PROCESS_H
28#define NIDAS_UTIL_PROCESS_H
42#include <nidas/Config.h>
44#ifdef HAVE_SYS_CAPABILITY_H
45#include <sys/capability.h>
48#include <ext/stdio_filebuf.h>
50namespace nidas {
namespace util {
128 const std::vector<std::string>& args,
129 const std::map<std::string, std::string>& env,
144 const std::vector<std::string>& args,
160 void kill(
int signal);
176 int wait(
bool hang,
int *status);
315 static bool getEnvVar(
const std::string& name,std::string& value);
317 static void setEnvVar(
const std::string& name,
const std::string& value);
360 mutable auto_ptr<__gnu_cxx::stdio_filebuf<char> >
_inbuf_ap;
372 mutable auto_ptr<__gnu_cxx::stdio_filebuf<char> >
_outbuf_ap;
384 mutable auto_ptr<__gnu_cxx::stdio_filebuf<char> >
_errbuf_ap;
A C++ wrapper for a POSIX mutex.
Definition ThreadSupport.h:161
Process provides an encapsulation of a spawned process, allowing the parent process to perform I/O wi...
Definition Process.h:58
static Mutex _envLock
Definition Process.h:390
static std::string expandEnvVars(std::string input)
Definition Process.cc:566
pid_t _pid
Definition Process.h:343
void closeOut()
Close the file descriptor and istream of the pipe connected to the standard out of the Process.
Definition Process.cc:167
static std::string _pidFile
Definition Process.h:341
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
std::istream & errStream()
Get the istream of the pipe that is connected to the standard error of the Process.
Definition Process.h:238
static void clearEffectiveCapability(int cap)
Definition Process.cc:495
auto_ptr< __gnu_cxx::stdio_filebuf< char > > _outbuf_ap
Definition Process.h:372
int getErrFd() const
Get the file descriptor of the pipe that is connected to the standard error of the Process.
Definition Process.h:230
static void removePidFile()
Remove the pid file.
Definition Process.cc:449
void closeErr()
Close the file descriptor and istream of the pipe connected to the standard error of the Process.
Definition Process.cc:175
void setOutFd(int val)
Definition Process.cc:143
int _errfd
File descriptor that is connected via a pipe to the standard error file descriptor of a spawned proce...
Definition Process.h:380
auto_ptr< std::istream > _outstream_ap
Definition Process.h:374
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:360
int getOutFd() const
Get the file descriptor of the pipe that is connected to the standard out of the Process.
Definition Process.h:208
int _outfd
File descriptor that is connected via a pipe to the standard out file descriptor of a spawned process...
Definition Process.h:368
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:622
int getInFd() const
Get the file descriptor of the pipe that is connected to the standard in of the Process.
Definition Process.h:185
Process & operator=(const Process &x)
Assignment operator.
Definition Process.cc:105
std::ostream & inStream()
Get the ostream of the pipe that is connected to the standard in of the Process.
Definition Process.h:192
int wait(bool hang, int *status)
Do a system wait on a process.
Definition Process.cc:364
auto_ptr< std::istream > _errstream_ap
Definition Process.h:386
void setErrFd(int val)
Definition Process.cc:151
int _infd
File descriptor that is connected via a pipe to the standard in file descriptor of a spawned process.
Definition Process.h:352
void closeIn()
Close the file descriptor and ostream of the pipe connected to the standard in of the Process.
Definition Process.cc:159
static unsigned long getMaxRSS()
Return the maximum resident set size of the current process, in bytes.
Definition Process.cc:703
static void setEnvVar(const std::string &name, const std::string &value)
Definition Process.cc:631
std::istream & outStream()
Get the istream of the pipe that is connected to the standard out of the Process.
Definition Process.h:216
auto_ptr< std::ostream > _instream_ap
Definition Process.h:362
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:680
~Process()
Destructor, which does very little.
Definition Process.cc:131
Process()
Default constructor.
Definition Process.cc:77
void setInFd(int val)
Definition Process.cc:135
pid_t getPid() const
The process id of the Process.
Definition Process.h:251
static void addEffectiveCapability(int cap)
Add an effective capability to this process.
Definition Process.cc:456
void kill(int signal)
Send a signal to the process.
Definition Process.cc:352
auto_ptr< __gnu_cxx::stdio_filebuf< char > > _errbuf_ap
Definition Process.h:384
static bool getEffectiveCapability(int cap)
Check if this process has an effective capability.
Definition Process.cc:532
static void clearEnv()
Remove any environment settings made by setEnvVar and release any memory allocated to put those setti...
Definition Process.cc:651
static std::map< std::string, char * > _environment
Definition Process.h:388
static pid_t checkPidFile(const std::string &pidFile)
Check if another process is running, using the named process id file.
Definition Process.cc:386
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31