URL: https://linuxfr.org/forums/astucesdivers/posts/x-window-top-xrootconsole Title: [X-Window] top + xrootconsole Authors: abraxas Date: 2005年08月06日T11:40:25+02:00 Tags: Score: 0 Voulant afficher un top sur mon bureau, j'ai naturellement lancé top | xrootconsole. Malheur, on voit des caractères hideux. man top me renseigne, je lance donc top -b | xrootconsole [et des option]. Et là, petit problème : top -b fait défiler des 'top', et donc ça défile dans la console, ce qui est évidemment inutilisable. J'ai donc écrit un (très laid) petit programme en C à glisser entre top et xrootconsole : #include <stdio.h> int read_line(FILE *f, char *s, int slength){ int i=0,l; while((l=fgetc(f))!='\n'){ if(l==EOF){ s[i]='0円'; return 1; }else{ s[i]=(unsigned char)l; i++; } if(i>=slength-1){ s[i]='\n'; s[i+1]='0円'; while((l=fgetc(f))!='\n' && l!=EOF); if(l==EOF) return 1; else break; //returns 0 } } s[i]='\n'; s[i+1]='0円'; return 0; } int get_proc_count(char *s){ int i=0, j=0; char tab[20]; while(s[i]!=' ') i++; while(s[i]==' ') i++; // while(s[i]!=' ') i++; //while(s[i]==' ') i++; //décommenter ces lignes si vous utilisez l'option -i avec top //while(s[i]!=' ') i++; //while(s[i]==' ') i++; while(s[i]!=' '){ tab[j]=s[i]; j++; i++; } tab[j]='0円'; return atoi(tab); } int min(int a, int b){ if(a<=b) return a; else return b; } int main(int argc, char *argv[]){ int lines_total=0, i, pcount; char buff[256]; if(argc<2){ printf("usage : toptop <line number>\n"); return 1; } lines_total=atoi(argv[1]); while(1){ if(read_line(stdin, buff, 255)){ //read first line fclose(stdout); return 0; }else printf("%s", buff); if(read_line(stdin, buff, 255)){ //read second line fclose(stdout); return 0; }else printf("%s", buff); pcount = get_proc_count(buff); //second line contains (active) tasks number for(i=0;i<min(5+pcount,lines_total-2);i++){ //print all lines, depending on the tasks number if(read_line(stdin, buff, 255)){ fclose(stdout); return 0; }else printf("%s", buff); } for(i=0;i<lines_total-8-pcount;i++) printf("\n"); //fill with empty lines fflush(stdout); while(strcmp(buff, "\n")){ //get lines until the end of the top output if(read_line(stdin, buff, 255)){ fclose(stdout); return 0; } } if(read_line(stdin, buff, 255)){ fclose(stdout); return 0; } } return 0; } Je peux donc faire un petit top -b | monprog <nombre_de_lignes> | xrootconsole -geometry <nb_colonnes>x+0+0 (il faut peut-être remplacer <nombre_de_lignes> par <nombre_de_lignes+1>, car ce programme est mal écrit), et ça marche : le top ne bouge pas, et s'il est trop long il est tronqué. Voilà, si ça intéresse quelqu'un, j'ai écrit un programme dans le même genre (couplé à un script) pour netstat, y'a qu'à demander. Bon pour df évidemment, y'a pas de problème. Bonnes vacances à tous.