1 #ifndef __JSYSTEMTOOLKIT__
2 #define __JSYSTEMTOOLKIT__
23 namespace JPP {
using namespace JSYSTEM; }
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();
275 shell <<
"which " << process << endl;
320 ls(
const std::string& option =
"")
332 void get(
JShell& shell,
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;
407 using namespace JSYSTEM;
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;
Auxiliary class for system information.
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.
static const char *const SH
Shell names.
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 std::string SPECIAL_CHARACTERS
Special characters.
static const char *const ZSH
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