1 #ifndef __JSYSTEMTOOLKIT__
2 #define __JSYSTEMTOOLKIT__
24 namespace JPP {
using namespace JSYSTEM; }
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();
276 shell <<
"which " << process << endl;
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;
337 cout <<
"exit " << status <<
";" << endl;
354 using namespace JSYSTEM;
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;
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
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.
then echo Variable JPP_DIR undefined exit fi source $JPP_DIR setenv sh $JPP_DIR &dev null set_variable
pid_t getPID(JShell &shell, const char *process)
Get process identifier.
*fatal Wrong number of arguments esac notice which
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.
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.
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