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 += \
updatable.cpp \
task.cpp \
controller.cpp \
generalstatus.cpp
generalstatus.cpp \
service.cpp
HEADERS += \
mainwindow.h \
......@@ -40,7 +41,8 @@ HEADERS += \
updatable.h \
task.h \
controller.h \
generalstatus.h
generalstatus.h \
service.h
FORMS += \
mainwindow.ui
#include "element.h"
Element::Element(QString & name) : name(name)
Element::Element()
{
}
......
......@@ -9,7 +9,7 @@
class Element : public Updatable
{
public:
Element(QString & name);
Element();
QString get_name();
QString get_status();
protected:
......
#include "elements.h"
Elements::Elements()
Elements::Elements() : proc("/proc/"), task_list(".listT")
{
}
......@@ -13,6 +13,20 @@ QStandardItemModel & Elements::getModel()
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:
private:
QStandardItemModel model;
QStandardItem *parent0 = model.invisibleRootItem();
QFile proc;
QFile task_list;
};
#endif // ELEMENTS_H
......@@ -14,6 +14,8 @@ GeneralStatus::GeneralStatus() : user_time(0), uptime("/proc/uptime"), meminfo("
meminfo.close();
user = getenv("USER");
GeneralStatus::update();
}
......@@ -95,3 +97,7 @@ int GeneralStatus::getNbTask()
{
return nbTask;
}
QString GeneralStatus::getUser()
{
return user;
}
......@@ -12,6 +12,7 @@ public:
int getMemTotal();
double getCPU();
int getNbTask();
QString getUser();
void update();
private:
int time;
......@@ -20,6 +21,7 @@ private:
double CPU;
int nbTask;
int user_time;
QString user;
QFile uptime;
QFile meminfo;
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"
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();
}
......@@ -22,6 +46,7 @@ void Task::update()
int new_utime = fields.at(13).toInt();
CPU = static_cast<double>(new_utime-utime);
utime = new_utime;
PPID = fields.at(3).toInt();
stat.close();
}
......@@ -47,3 +72,11 @@ double Task::getMem()
{
return mem;
}
int Task::getPPID()
{
return PPID;
}
QString Task::getUser()
{
return user;
}
......@@ -10,19 +10,23 @@
class Task : Element
{
public:
Task(QString & name, int PID);
Task(int PID);
void update();
void sendSignal(int sig);
int getPID();
double getCPU();
int getUtime();
double getMem();
int getPPID();
QString getUser();
private:
int PID;
double CPU;
int utime;
double mem;
int PPID;
QFile stat;
QString user;
};
#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