Voîla je presente devant vous le résultat de mon éffort et de votre aide
Biensûr il reste encor beaucoup à faire .
si il y as qulque chose à ajouter ou à modifier ... dite le moi :P
MERCI
/*******************************************************************************
merci à John Doe, Krunch et daggett sur le forum du site http://linuxfr.org/
merci pour leur collaboration.
si ce programme marche même à moitié c'est à cause de leur coup de pouce
un gros coup de pouce il faud bien le dire :-)
programme codé par xenos : xenos.psy@gmail.com
le lun, 2 oct 2006
NOTE : projet en cour de développement
gcc -o cmemstat cmemstat.c -lcurses -lpthread
PAR XENOS; TAMDY Mohamed AMINE
********************************************************************************/
#include <stdlib.h>
#include <curses.h>
#include <time.h>
#include <pthread.h>
#include <unistd.h>
#include <linux/unistd.h> /* les macros _syscallX */
#include <linux/kernel.h> /* pour struct sysinfo */
#include <sys/utsname.h>
#include <sched.h>
#define ENTER 13
#define ESCAPE 27
#define PROC_MEM "/proc/meminfo"
#define PROC_CPU "/proc/"
#define PROC_HDD "/proc/"
// question forum http://linuxfr.org/forums/19/18977.html
//setpriority(2), sched_yield(2)
WINDOW *menubar, *memwin, *cpuwin, *hddwin, *sup_info;
WINDOW *sub_mem, *sub_cpu, *sub_hdd;
time_t d_time;
FILE *meminfo;
struct sysinfo s_info;
struct utsname u_name;
void init_curses(void) {
initscr();
start_color();
init_pair(1, COLOR_WHITE, COLOR_BLUE);
init_pair(2, COLOR_BLUE, COLOR_WHITE);
init_pair(3, COLOR_RED, COLOR_WHITE);
init_pair(4, COLOR_RED, COLOR_YELLOW);
init_pair(5, COLOR_GREEN, COLOR_BLUE);
init_pair(6, COLOR_RED, COLOR_BLUE);
curs_set(0);
noecho();
keypad(stdscr, TRUE);
}
void menu_bar(void) {
menubar = subwin(stdscr, 1,63, 26,0);
wbkgd(menubar, COLOR_PAIR(2));
wattron(menubar, COLOR_PAIR(3));
waddstr(menubar, "ESC");
wattroff(menubar, COLOR_PAIR(3));
waddstr(menubar, " : EXIT |");
wattron(menubar, COLOR_PAIR(3));
waddstr(menubar, u_name.sysname);
wattroff(menubar, COLOR_PAIR(3));
waddstr(menubar, "|");
wattron(menubar, COLOR_PAIR(3));
waddstr(menubar, u_name.machine);
wattroff(menubar, COLOR_PAIR(3));
waddstr(menubar, "|");
wattron(menubar, COLOR_PAIR(3));
waddstr(menubar, u_name.release);
wattroff(menubar, COLOR_PAIR(3));
waddstr(menubar, "| ");
wprintw(menubar, "%s", ctime(&d_time));
}
void set_title(void) {
wmove(memwin, 0, 2);
wattron(memwin, COLOR_PAIR(5));
waddstr(memwin, "Utilisation de la RAM");
wattroff(memwin, COLOR_PAIR(5));
wmove(cpuwin, 0, 2);
wattron(cpuwin, COLOR_PAIR(5));
waddstr(cpuwin, "Info CPU");
wattroff(cpuwin, COLOR_PAIR(5));
wmove(hddwin, 0, 2);
wattron(hddwin, COLOR_PAIR(5));
waddstr(hddwin, "Info Hard Disk Drive");
wattroff(hddwin, COLOR_PAIR(5));
}
void create_sub_win(void) {
sub_mem = subwin(memwin, 23, 29, 1, 1);
// sub_cpu = subwin(cpuwin, 5, 15, 1, 20);
// box(sub_cpu, ACS_VLINE, ACS_HLINE);
// sub_hdd = subwin(hddwin, 5, 15, 1, 15);
// box(sub_hdd, ACS_VLINE, ACS_HLINE);
}
void info_sup(void) {
sysinfo(&s_info);
werase(sup_info);
box(sup_info, ACS_VLINE, ACS_HLINE);
wmove(sup_info, 1, 1);
wprintw(sup_info, "- uptime : ");
wattron(sup_info, COLOR_PAIR(6));
wprintw(sup_info, "%d", s_info.uptime);
wattroff(sup_info, COLOR_PAIR(6));
wprintw(sup_info, " sec");
wmove(sup_info, 3, 1);
wprintw(sup_info, "- processus active : ");
wattron(sup_info, COLOR_PAIR(6));
wprintw(sup_info, "%d", s_info.procs);
wattroff(sup_info, COLOR_PAIR(6));
wrefresh(sup_info);
}
void *thread_info(void *x) {
int i=0;
char value[256];
if((meminfo = fopen(PROC_MEM, "r")) != NULL) {
while(1) {
werase(sub_mem);
while(fgets(value, sizeof(value), meminfo)) {
if(value[0] != '#') {
i+=1;
wmove(sub_mem, i, 1);
wprintw(sub_mem, "- %s", value);
}
}
rewind(meminfo);
i=0;
info_sup();
wrefresh(sub_mem);
sleep(1);
//sched_yield();
}
}
}
int main(void) {
int key=0, i=0;
struct tm up_time;
pthread_t thread_id;
time(&d_time);
uname(&u_name);
init_curses(); // initialisation de curses
bkgd(COLOR_PAIR(1));
memwin = subwin(stdscr,26,33,0,0);
box(memwin, ACS_VLINE, ACS_HLINE);
cpuwin = subwin(stdscr, 10, 30, 0, 33);
box(cpuwin, ACS_VLINE, ACS_HLINE);
hddwin = subwin(stdscr, 11, 30, 10, 33);
box(hddwin, ACS_VLINE, ACS_HLINE);
sup_info = subwin(stdscr, 5, 30, 21, 33);
box(sup_info, ACS_VLINE, ACS_HLINE);
menu_bar();
set_title();
create_sub_win();
refresh();
//l'appelle du thread
if(pthread_create(&thread_id, NULL, thread_info, "0") != 0) {
fprintf(stderr, "Error : Thread error !!!\r\n");
return EXIT_FAILURE;
}
do {
key = getch();
} while(key != ESCAPE);
pthread_cancel(thread_id); // arrêt du thread
fclose(meminfo);
delwin(cpuwin);
delwin(memwin);
delwin(menubar);
endwin();
return EXIT_SUCCESS;
}
# projet terminer à 50%
Posté par xenos . En réponse au message minimiser l'utilisation du CPU. Évalué à 1.