1 #ifndef __JSYSTEMTOOLKIT__ 
    2 #define __JSYSTEMTOOLKIT__ 
   33   static const char* 
const  SH    =  
"sh";
 
   34   static const char* 
const  ZSH   =  
"zsh";
 
   35   static const char* 
const  KSH   =  
"ksh";
 
   36   static const char* 
const  BASH  =  
"bash";
 
   37   static const char* 
const  CSH   =  
"csh";
 
   38   static const char* 
const  TCSH  =  
"tcsh";
 
   57     shell << 
"ps -o %mem= -p " << pid << endl;
 
  102     shell << 
"ps -o %cpu= -p " << pid << endl;
 
  104     if (shell.
get(value))
 
  147     shell << 
"ps -o pid= -C " << process << endl;
 
  179     shell << 
"ps -o ppid= -p " << pid << endl;
 
  210     static string value = 
"";
 
  214       pid_t pid = getppid();
 
  216       shell << 
"ps -o ppid= -o args= -p " << pid << endl;
 
  218       if (shell >> pid >> value) {
 
  222         if (!value.empty() && value[0] == 
'-') {
 
  223           value = value.substr(1);
 
  228         static_cast<istream&
>(shell).clear();
 
  270   inline const std::string 
which(
JShell& shell, 
const char* process)
 
  276     shell << 
"which " << process << endl;
 
  292   inline const std::string 
which(
const char* process)
 
  303   inline void gprint(
const std::string& message)
 
  307     istringstream is(message);
 
  309     for (
string buffer; 
getline(is, buffer); ) {
 
  311       if (!buffer.empty()) {
 
  313         for (string::size_type i = 0; i != buffer.size(); ++i) {
 
  315             buffer.insert(i++, 
"\\");
 
  319         cout << 
"echo " << buffer << 
";" << endl;
 
  331   inline int gexit(
int status, 
const std::string& message = 
"")
 
  337     cout << 
"exit " << status << 
";" << endl;
 
  351   inline void set_variable(
const std::string& name, 
const std::string& value)
 
  356     static const string shell = 
getShell();
 
  358     string buffer(value);
 
  360     if (buffer.find(
' ') != string::npos) {
 
  361       buffer = 
"\"" + buffer + 
"\"";
 
  364     if        (shell.find(
ZSH)  != string::npos ||
 
  365                shell.find(
KSH)  != string::npos ||
 
  366                shell.find(
BASH) != string::npos) {
 
  368       cout << 
"export " << name << 
"=" << buffer << 
";" << endl;
 
  370     } 
else if (shell.find(
CSH)  != string::npos ||
 
  371                shell.find(
TCSH) != string::npos) {
 
  373       cout << 
"setenv " << name << 
" " << buffer << 
";" << endl;
 
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
 
Shell interaction via I/O streams.
 
Exception for system call.
 
The JShell clas can be used to interact with the shell via I/O streams.
 
static JShell & getInstance()
Get reference to unique instance of this class object.
 
JShell & flush(std::ostream &out=null)
Extracts characters from this shell and flush them to the given output stream until the prompt is rea...
 
bool getline(std::string &buffer, const char eol='\n')
Get line of text.
 
bool get(T &value)
Get value.
 
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
 
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
 
Auxiliary classes and methods for operating system calls.
 
float getMemoryUsage()
Get memory usage in percent of this process.
 
static const char *const ZSH
 
static const char *const TCSH
 
unsigned long long int getRAM()
Get RAM of this CPU.
 
static const char *const BASH
 
pid_t getPID(const char *process)
Get process identifier.
 
pid_t getParentID(const pid_t pid)
Get parent process identifier.
 
static const char *const SH
Shell names.
 
static const std::string SPECIAL_CHARACTERS
 
int gexit(int status, const std::string &message="")
Exit method.
 
static const char *const CSH
 
float getCpuUsage()
Get cpu usage in percent of this process.
 
std::string getShell()
Get shell name of this process.
 
const std::string which(const char *process)
Get process path.
 
static const char *const KSH
 
void gprint(const std::string &message)
Print method.
 
void set_variable(const std::string &name, const std::string &value)
Set environment variable.
 
Auxiliary class for system information.
 
unsigned long long int getTotalRAM() const
Get total RAM.