Skip to content
Extraits de code Groupes Projets
Valider 5b8a9633 rédigé par Romain DERRE's avatar Romain DERRE
Parcourir les fichiers

ajout de service.[h/cpp]

fonction pour obtenir le user principal dans generalstatus et le user
d'une task
parent 0e62a55c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -31,7 +31,8 @@ SOURCES += \ ...@@ -31,7 +31,8 @@ SOURCES += \
updatable.cpp \ updatable.cpp \
task.cpp \ task.cpp \
controller.cpp \ controller.cpp \
generalstatus.cpp generalstatus.cpp \
service.cpp
HEADERS += \ HEADERS += \
mainwindow.h \ mainwindow.h \
...@@ -40,7 +41,8 @@ HEADERS += \ ...@@ -40,7 +41,8 @@ HEADERS += \
updatable.h \ updatable.h \
task.h \ task.h \
controller.h \ controller.h \
generalstatus.h generalstatus.h \
service.h
FORMS += \ FORMS += \
mainwindow.ui mainwindow.ui
#include "element.h" #include "element.h"
Element::Element(QString & name) : name(name) Element::Element()
{ {
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
class Element : public Updatable class Element : public Updatable
{ {
public: public:
Element(QString & name); Element();
QString get_name(); QString get_name();
QString get_status(); QString get_status();
protected: protected:
......
#include "elements.h" #include "elements.h"
Elements::Elements() Elements::Elements() : proc("/proc/"), task_list(".listT")
{ {
} }
...@@ -13,6 +13,20 @@ QStandardItemModel & Elements::getModel() ...@@ -13,6 +13,20 @@ QStandardItemModel & Elements::getModel()
void Elements::update() void Elements::update()
{ {
system("ls /proc | grep '[0-9]' > .listT");
if(!task_list.open(QIODevice::ReadOnly)) {
QMessageBox::information(0, "error", task_list.errorString());
}
QTextStream in(&task_list);
while(!in.atEnd()) {
int pid = in.readLine().toInt();
//model->appendRow(line);
}
task_list.close();
} }
...@@ -16,6 +16,8 @@ public: ...@@ -16,6 +16,8 @@ public:
private: private:
QStandardItemModel model; QStandardItemModel model;
QStandardItem *parent0 = model.invisibleRootItem(); QStandardItem *parent0 = model.invisibleRootItem();
QFile proc;
QFile task_list;
}; };
#endif // ELEMENTS_H #endif // ELEMENTS_H
...@@ -14,6 +14,8 @@ GeneralStatus::GeneralStatus() : user_time(0), uptime("/proc/uptime"), meminfo(" ...@@ -14,6 +14,8 @@ GeneralStatus::GeneralStatus() : user_time(0), uptime("/proc/uptime"), meminfo("
meminfo.close(); meminfo.close();
user = getenv("USER");
GeneralStatus::update(); GeneralStatus::update();
} }
...@@ -95,3 +97,7 @@ int GeneralStatus::getNbTask() ...@@ -95,3 +97,7 @@ int GeneralStatus::getNbTask()
{ {
return nbTask; return nbTask;
} }
QString GeneralStatus::getUser()
{
return user;
}
...@@ -12,6 +12,7 @@ public: ...@@ -12,6 +12,7 @@ public:
int getMemTotal(); int getMemTotal();
double getCPU(); double getCPU();
int getNbTask(); int getNbTask();
QString getUser();
void update(); void update();
private: private:
int time; int time;
...@@ -20,6 +21,7 @@ private: ...@@ -20,6 +21,7 @@ private:
double CPU; double CPU;
int nbTask; int nbTask;
int user_time; int user_time;
QString user;
QFile uptime; QFile uptime;
QFile meminfo; QFile meminfo;
QFile stat; QFile stat;
......
#include "service.h"
Service::Service()
{
}
Service::update()
{
}
int Service::get_nbTask()
{
return nbTask;
}
QString Service::get_details()
{
return details;
}
#ifndef SERVICE_H
#define SERVICE_H
#include "element.h"
class Service : public Element
{
public:
Service();
int get_nbTask();
QString get_details();
private:
int nbTask;
QString details;
};
#endif // SERVICE_H
#include "task.h" #include "task.h"
Task::Task(QString & name, int PID) : Element(name), PID(PID), utime(0), stat("/proc/"+QString::number(PID)+"/stat") Task::Task(int PID) : PID(PID), utime(0), stat("/proc/"+QString::number(PID)+"/stat")
{ {
QFile cmd("/proc"+QString::number(PID)+"/comm");
if(!cmd.open(QIODevice::ReadOnly)) {
QMessageBox::information(0, "error", cmd.errorString());
}
QTextStream in(&cmd);
name = in.readLine();
cmd.close();
QString command("ls -la /proc/"+QString::number(PID)+" | grep ' \.' > .userT");
system(command.toStdString().c_str());
QFile task_user(".userT");
if(!task_user.open(QIODevice::ReadOnly)) {
QMessageBox::information(0, "error", task_user.errorString());
}
QTextStream in2(&task_user);
QStringList fields = in2.readLine().split(" ");
user = fields.at(fields.length()-8);
task_user.close();
Task::update(); Task::update();
} }
...@@ -22,6 +46,7 @@ void Task::update() ...@@ -22,6 +46,7 @@ void Task::update()
int new_utime = fields.at(13).toInt(); int new_utime = fields.at(13).toInt();
CPU = static_cast<double>(new_utime-utime); CPU = static_cast<double>(new_utime-utime);
utime = new_utime; utime = new_utime;
PPID = fields.at(3).toInt();
stat.close(); stat.close();
} }
...@@ -47,3 +72,11 @@ double Task::getMem() ...@@ -47,3 +72,11 @@ double Task::getMem()
{ {
return mem; return mem;
} }
int Task::getPPID()
{
return PPID;
}
QString Task::getUser()
{
return user;
}
...@@ -10,19 +10,23 @@ ...@@ -10,19 +10,23 @@
class Task : Element class Task : Element
{ {
public: public:
Task(QString & name, int PID); Task(int PID);
void update(); void update();
void sendSignal(int sig); void sendSignal(int sig);
int getPID(); int getPID();
double getCPU(); double getCPU();
int getUtime(); int getUtime();
double getMem(); double getMem();
int getPPID();
QString getUser();
private: private:
int PID; int PID;
double CPU; double CPU;
int utime; int utime;
double mem; double mem;
int PPID;
QFile stat; QFile stat;
QString user;
}; };
#endif // TASK_H #endif // TASK_H
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter