Go to the documentation of this file.    1 #ifndef __JSYSTEMTOOLKIT__ 
    2 #define __JSYSTEMTOOLKIT__ 
   32   static const char* 
const  SH    =  
"sh";
 
   33   static const char* 
const  ZSH   =  
"zsh";
 
   34   static const char* 
const  KSH   =  
"ksh";
 
   35   static const char* 
const  BASH  =  
"bash";
 
   36   static const char* 
const  CSH   =  
"csh";
 
   37   static const char* 
const  TCSH  =  
"tcsh";
 
   56     shell << 
"ps -o %mem= -p " << pid << endl;
 
  101     shell << 
"ps -o %cpu= -p " << pid << endl;
 
  103     if (shell.
get(value))
 
  146     shell << 
"ps -o pid= -C " << process << endl;
 
  178     shell << 
"ps -o ppid= -p " << pid << endl;
 
  209     static string value = 
"";
 
  213       pid_t pid = getppid();
 
  215       shell << 
"ps -o ppid= -o args= -p " << pid << endl;
 
  217       if (shell >> pid >> value) {
 
  221         if (!value.empty() && value[0] == 
'-') {
 
  222           value = value.substr(1);
 
  227         static_cast<istream&>(shell).clear();
 
  269   inline const std::string 
which(
JShell& shell, 
const char* process)
 
  275     shell << 
"which " << process << endl;
 
  291   inline const std::string 
which(
const char* process)
 
  320     ls(
const std::string& option = 
"")
 
  336       string buffer = 
"ls";
 
  338       if (!option.empty()) {
 
  339         buffer += 
" " + option;
 
  342       shell << buffer << endl;
 
  344       while (shell.
getline(buffer)) {
 
  356   inline void gprint(
const std::string& message)
 
  360     istringstream is(message);
 
  362     for (
string buffer; 
getline(is, buffer); ) {
 
  364       if (!buffer.empty()) {
 
  366         for (string::size_type i = 0; i != buffer.size(); ++i) {
 
  368             buffer.insert(i++, 
"\\");
 
  372         cout << 
"echo " << buffer << 
";" << endl;
 
  384   inline int gexit(
int status, 
const std::string& message = 
"")
 
  390     cout << 
"exit " << status << 
";" << endl;
 
  404   inline void set_variable(
const std::string& name, 
const std::string& value)
 
  409     static const string shell = 
getShell();
 
  411     string buffer(value);
 
  413     if (buffer.find(
' ') != string::npos) {
 
  414       buffer = 
"\"" + buffer + 
"\"";
 
  417     if        (shell.find(
ZSH)  != string::npos ||
 
  418                shell.find(
KSH)  != string::npos ||
 
  419                shell.find(
BASH) != string::npos) {
 
  421       cout << 
"export " << name << 
"=" << buffer << 
";" << endl;
 
  423     } 
else if (shell.find(
CSH)  != string::npos ||
 
  424                shell.find(
TCSH) != string::npos) {
 
  426       cout << 
"setenv " << name << 
" " << buffer << 
";" << endl;
 
 
static const char *const CSH
 
static const char *const KSH
 
static const char *const SH
Shell names.
 
void gprint(const std::string &message)
Print method.
 
static const char *const TCSH
 
The JShell clas can be used to interact with the shell via I/O streams.
 
void set_variable(const std::string &name, const std::string &value)
Set environment variable.
 
pid_t getParentID(const pid_t pid)
Get parent process identifier.
 
Exception for system call.
 
ls(JShell &shell, const std::string &option="")
Constructor.
 
const std::string which(const char *process)
Get process path.
 
ls(const std::string &option="")
Constructor.
 
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
 
float getMemoryUsage()
Get memory usage in percent of this process.
 
void get(JShell &shell, const std::string option="")
add list files.
 
static const char *const ZSH
 
Auxiliary classes and methods for operating system calls.
 
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
 
Auxiliary class to list files.
 
unsigned long long int getTotalRAM() const
Get total RAM.
 
bool get(T &value)
Get value.
 
JShell & flush(std::ostream &out=null)
Extracts characters from this shell and flush them to the given output stream until the prompt is rea...
 
float getCpuUsage()
Get cpu usage in percent of this process.
 
pid_t getPID(const char *process)
Get process identifier.
 
bool getline(std::string &buffer, const char eol='\n')
Get line of text.
 
Auxiliary class for system information.
 
int gexit(int status, const std::string &message="")
Exit method.
 
static const std::string SPECIAL_CHARACTERS
 
static const char *const BASH
 
static JShell & getInstance()
Get reference to unique instance of this class object.
 
unsigned long long int getRAM()
Get RAM of this CPU.
 
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
 
std::string getShell()
Get shell name of this process.