1 #ifndef __JSYSTEMTOOLKIT__
2 #define __JSYSTEMTOOLKIT__
23 namespace JPP {
using namespace JSYSTEM; }
32 static const char*
const ZSH =
"zsh";
33 static const char*
const KSH =
"ksh";
34 static const char*
const BASH =
"bash";
35 static const char*
const CSH =
"csh";
36 static const char*
const TCSH =
"tcsh";
52 shell <<
"ps -o %mem= -p " << pid << endl;
97 shell <<
"ps -o %cpu= -p " << pid << endl;
142 shell <<
"ps -o pid= -C " << process << endl;
174 shell <<
"ps -o ppid= -p " << pid << endl;
205 static string value =
"";
209 pid_t pid = getppid();
211 shell <<
"ps -o ppid= -o args= -p " << pid << endl;
213 if (shell >> pid >> value) {
217 if (!value.empty() && value[0] ==
'-') {
218 value = value.substr(1);
223 static_cast<istream&
>(shell).clear();
265 inline const std::string
which(
JShell& shell,
const char* process)
271 shell <<
"which " << process << endl;
287 inline const std::string
which(
const char* process)
316 ls(
const std::string& option =
"")
328 void get(
JShell& shell,
const std::string option =
"")
332 string buffer =
"ls";
334 if (!option.empty()) {
335 buffer +=
" " + option;
338 shell << buffer << endl;
340 while (shell.getline(buffer)) {
352 inline void gprint(
const std::string& message)
356 istringstream is(message);
358 for (
string buffer;
getline(is, buffer); ) {
359 cout <<
"echo \"" << buffer <<
"\";" << endl;
370 inline int gexit(
int status,
const std::string& message =
"")
376 cout <<
"exit " << status << endl;
390 inline void set_variable(
const std::string& name,
const std::string& value)
393 using namespace JSYSTEM;
395 static const string shell =
getShell();
397 string buffer(value);
399 if (buffer.find(
' ') != string::npos) {
400 buffer =
"\"" + buffer +
"\"";
403 if (shell.find(
ZSH) != string::npos ||
404 shell.find(
KSH) != string::npos ||
405 shell.find(
BASH) != string::npos)
407 cout <<
"export " << name <<
"=" << buffer <<
";" << endl;
409 else if (shell.find(
CSH) != string::npos ||
410 shell.find(
TCSH) != string::npos)
412 cout <<
"setenv " << name <<
" " << buffer <<
";" << endl;
Auxiliary class for file status.
The JShell clas can be used to interact with the shell via I/O streams.
std::string getShell(JShell &shell)
Get shell name.
float getMemoryUsage(JShell &shell, const pid_t pid)
Get memory usage in percent of given process identifier.
void set_variable(const std::string &name, const std::string &value)
Set environment variable.
static const char *const TCSH
void gprint(const std::string &message)
Print method.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
ls(const std::string &option="")
Constructor.
float getCpuUsage(JShell &shell, const pid_t pid)
Get cpu usage in percent of given process identifier.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
pid_t getPID(JShell &shell, const char *process)
Get process identifier.
JShell & flush(std::ostream &out=null)
Extracts characters from this shell and flush them to the given output stream until the prompt is rea...
static const char *const ZSH
Shell names.
bool get(T &value)
Get value.
int gexit(int status, const std::string &message="")
Exit method.
const std::string which(JShell &shell, const char *process)
Get process path.
bool getline(std::string &buffer, const char eol= '\n')
Get line of text.
ls(JShell &shell, const std::string &option="")
Constructor.
static JShell & getInstance()
Get reference to unique instance of this class object.
unsigned long long int getRAM()
Get RAM of this CPU.
Shell interaction via I/O streams.
Exception for system call.
unsigned long long int getTotalRAM() const
Get total RAM.
Auxiliary class to list files.
static const char *const BASH
pid_t getParentID(JShell &shell, pid_t pid)
Get parent process identifier.
static const char *const KSH
static const char *const CSH