1 #ifndef __JSYSTEMTOOLKIT__
2 #define __JSYSTEMTOOLKIT__
25 namespace JPP {
using namespace JSYSTEM; }
34 static const char*
const SH =
"sh";
35 static const char*
const ZSH =
"zsh";
36 static const char*
const KSH =
"ksh";
37 static const char*
const BASH =
"bash";
38 static const char*
const CSH =
"csh";
39 static const char*
const TCSH =
"tcsh";
58 shell <<
"ps -o %mem= -p " << pid << endl;
103 shell <<
"ps -o %cpu= -p " << pid << endl;
105 if (shell.
get(value))
148 shell <<
"ps -o pid= -C " << process << endl;
180 shell <<
"ps -o ppid= -p " << pid << endl;
211 static string value =
"";
215 pid_t pid = getppid();
217 shell <<
"ps -o ppid= -o args= -p " << pid << endl;
219 if (shell >> pid >> value) {
223 if (!value.empty() && value[0] ==
'-') {
224 value = value.substr(1);
229 static_cast<istream&
>(shell).clear();
271 inline const std::string
which(
JShell& shell,
const char* process)
277 shell <<
"which " << process << endl;
293 inline const std::string
which(
const char* process)
310 ls(
const std::string& dir)
312 DIR* top = opendir(dir.c_str());
316 for (dirent* i; (i = readdir(top)) != NULL; ) {
317 this->push_back(i->d_name);
331 inline void gprint(
const std::string& message)
335 istringstream
is(message);
337 for (
string buffer;
getline(is, buffer); ) {
339 if (!buffer.empty()) {
341 for (string::size_type i = 0; i != buffer.size(); ++i) {
343 buffer.insert(i++,
"\\");
347 cout <<
"echo " << buffer <<
";" << endl;
359 inline int gexit(
int status,
const std::string& message =
"")
365 cout <<
"exit " << status <<
";" << endl;
382 using namespace JSYSTEM;
384 static const string shell =
getShell();
386 string buffer(value);
388 if (buffer.find(
' ') != string::npos) {
389 buffer =
"\"" + buffer +
"\"";
392 if (shell.find(
ZSH) != string::npos ||
393 shell.find(
KSH) != string::npos ||
394 shell.find(
BASH) != string::npos) {
396 cout <<
"export " << name <<
"=" << buffer <<
";" << endl;
398 }
else if (shell.find(
CSH) != string::npos ||
399 shell.find(
TCSH) != string::npos) {
401 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.
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.
then echo Enter input within $TIMEOUT_S seconds echo n User name
do echo Generating $dir eval DIR
then echo Variable JPP_DIR undefined exit fi source $JPP_DIR setenv sh $JPP_DIR &dev null set_variable
float getCpuUsage(JShell &shell, const pid_t pid)
Get cpu usage in percent of given process identifier.
ls(const std::string &dir)
Constructor.
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.
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 data structure to list files in directory.
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