|
@@ -14,13 +14,18 @@
|
|
|
#include "constante.h"
|
|
|
|
|
|
typedef struct{
|
|
|
- char* path;
|
|
|
- int pid;
|
|
|
- int uid;
|
|
|
- char state;
|
|
|
- char* cmd;
|
|
|
+ char* path; //Chemin vers le dossier du processus /./proc/[pid]/
|
|
|
+ int pid; //Le pid
|
|
|
+ int uid; //Le uid du proprietaire
|
|
|
+ char state; //L'etat
|
|
|
+ char* cmd; //La commande
|
|
|
}processus;
|
|
|
|
|
|
+/**
|
|
|
+ * Indique si une string est un nombre
|
|
|
+ * @param char* Le string
|
|
|
+ * @return Vrai/Faux
|
|
|
+ */
|
|
|
boolean is_numeric(const char* str){
|
|
|
while(*str){
|
|
|
if(*str < '0' || *str > '9'){
|
|
@@ -31,6 +36,10 @@ boolean is_numeric(const char* str){
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Tri les processus par pid croissant
|
|
|
+ * @param processus** Le tableau de processus
|
|
|
+ */
|
|
|
void sort_pid(processus** proc, int size){
|
|
|
processus* tmp;
|
|
|
int index;
|
|
@@ -45,6 +54,11 @@ void sort_pid(processus** proc, int size){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Liste les processus actifs
|
|
|
+ * @param int* Le nombre de processus actif
|
|
|
+ * @return processus** La liste
|
|
|
+ */
|
|
|
processus** list_process(int* nb){
|
|
|
struct dirent** dir;
|
|
|
struct stat info;
|
|
@@ -113,6 +127,11 @@ processus** list_process(int* nb){
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Lecture du fichier status d'un processus
|
|
|
+ * @param processus* Le processus
|
|
|
+ * @return Reussite
|
|
|
+ */
|
|
|
boolean read_status(processus* proc){
|
|
|
char* file;
|
|
|
int length, fd;
|
|
@@ -160,6 +179,11 @@ boolean read_status(processus* proc){
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Lecture du fichier comm d'un processus
|
|
|
+ * @param processus* Le processus
|
|
|
+ * @return Reussite
|
|
|
+ */
|
|
|
boolean read_comm(processus* proc){
|
|
|
char* file;
|
|
|
int length, fd;
|
|
@@ -218,6 +242,11 @@ boolean read_comm(processus* proc){
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Lecture du fichier cmdline d'un processus
|
|
|
+ * @param processus* Le processus
|
|
|
+ * @return Reussite
|
|
|
+ */
|
|
|
boolean read_cmd(processus* proc){
|
|
|
char* file;
|
|
|
int length, fd;
|
|
@@ -278,6 +307,10 @@ boolean read_cmd(processus* proc){
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Affiche les infos d'un processus
|
|
|
+ * @param processus* Le processus
|
|
|
+ */
|
|
|
void printps(processus* proc){
|
|
|
struct passwd* user;
|
|
|
//Recup le nom de l'utilisateur
|
|
@@ -304,9 +337,13 @@ int main(){
|
|
|
for(int i = 0; i < total; i++){
|
|
|
//Recup info manquante
|
|
|
if(!read_status(proc[i])){
|
|
|
+ free(proc[i]->path);
|
|
|
+ free(proc[i]);
|
|
|
continue;
|
|
|
}
|
|
|
if(!read_cmd(proc[i])){
|
|
|
+ free(proc[i]->path);
|
|
|
+ free(proc[i]);
|
|
|
continue;
|
|
|
}
|
|
|
//Affiche
|