Linux Task Manager

Source: Internet
Author: User

Compiled in redhat2.4.20-8:

The program window is compiled by the gglad tool, and the source code is not easy to paste. Only the code of some callback functions is provided:

1. "exit" button callback function:

Void
On_button9_clicked (gtkbutton * button,
Gpointer user_data)
{
Gtk_main_quit ();
}

2. "shutdown" button callback function:

Void
On_button10_clicked (gtkbutton * button,
Gpointer user_data)
{
System ("halt ");
}

3. "restart" button callback function:

Void
On_button11_clicked (gtkbutton * button,
Gpointer user_data)
{
System ("reboot ");
}

4. "Host Name" character block callback function:

Void
On_label38_realize (gtkwidget * widget,
Gpointer user_data)
{
File * FP;
Char Buf [256];
Fp = fopen ("/proc/sys/kernel/hostname", "R ");
Fgets (BUF, 256, FP );
Fclose (FP );
Gtk_label_set_text (widget, Buf );
}

5. "CPU model" character block callback function:

Void
On_label45_realize (gtkwidget * widget,
Gpointer user_data)
{

File * FP;
Int I, j = 0;
Char Buf [256], buf1 [256];
Fp = fopen ("/proc/cpuinfo", "R ");
For (I = 0; I <5; I ++ ){
Fgets (BUF, 256, FP );
}
For (I = 0; I <256; I ++ ){
If (BUF [I] = ':') break;
}
I + = 2;
For (; I <256; I ++ ){
If (BUF [I] = '') break;
}
I + = 1;
While (I <256 ){
If (BUF [I] = ''){
I ++;
}
Else {
Buf1 [J] = Buf [I];
J ++;
I ++;
}
}
Fclose (FP );
Gtk_label_set_text (widget, buf1); // CPU Model
}

6. "CPU clock speed" callback function:

Void
On_label46_realize (gtkwidget * widget,
Gpointer user_data)
{

File * FP;
Int I, j = 0;
Char Buf [256], buf1 [256];
Fp = fopen ("/proc/cpuinfo", "R ");
For (I = 0; I <7; I ++ ){
Fgets (BUF, 256, FP );
}
For (I = 0; I <256; I ++ ){
If (BUF [I] = ':') break;
}
I + = 2;
J = 0;
For (; I <256; I ++ ){
If (BUF [I] = '') break;
Else {
Buf1 [J] = Buf [I];
J ++;
}
}
Buf1 [J] = '/0 ';
Fclose (FP );
Gtk_label_set_text (widget, buf1); // CPU Model
}

7. "System Version Number" callback function:

Void
On_label39_realize (gtkwidget * widget,
Gpointer user_data)
{
File * FP;
Char Buf [256];
Fp = fopen ("/proc/sys/kernel/osrelease", "R ");
Fgets (BUF, 256, FP );
Fclose (FP );
Gtk_label_set_text (widget, Buf );
}

8. "system running time" callback function:

Void timeout_label40 (gtkwidget * widget, gpointer user_data ){

File * FP;
Int I, J;
Char Buf [64], buf1 [64];
Fp = fopen ("/proc/uptime", "R ");
Fgets (BUF, 64, FP );
J = 0;
For (I = 0; I <64; I ++ ){
If (BUF [I] = '') break;
Else {
Buf1 [J] = Buf [I];
J ++;
}
}
Buf1 [J] = '/0 ';
Fclose (FP );

Gtk_label_set_text (widget, buf1 );
}

Void
On_label40_realize (gtkwidget * widget,
Gpointer user_data)
{
Gtk_timeout_add (200, timeout_label40, widget );
}

9. "CPU running time" callback function:

Void timeout_label42 (gtkwidget * widget, gpointer user_data)
{

File * FP;
Int I, J;
Char Buf [64], buf1 [64];
Fp = fopen ("/proc/uptime", "R ");
Fgets (BUF, 64, FP );
For (I = 0; I <64; I ++ ){
If (BUF [I] = '') break;
}
I ++;
J = 0;
For (; I <64; I ++ ){
If (BUF [I] = '') break;
Else {
Buf1 [J] = Buf [I];
J ++;
}
}
Buf1 [J] = '//';
Buf1 [J + 1] = '0 ';
Fclose (FP );
Gtk_label_set_text (widget, buf1 );
}

Void
On_label42_realize (gtkwidget * widget,
Gpointer user_data)
{
Gtk_timeout_add (200, timeout_label42, widget );
}

10. "memory information" callback function:

Void
On_label51_realize (gtkwidget * widget,
Gpointer user_data)
{
File * FP;
Int I, J;
Char Buf [256], buf1 [256];
Fp = fopen ("/proc/meminfo", "R ");
Fgets (BUF, 256, FP );
Fgets (BUF, 256, FP );
For (I = 0; I <256; I ++ ){
If (BUF [I] = ':') break;
}
I ++;
For (; I <256; I ++ ){
If (BUF [I]! = '') Break;
}
J = 0;
For (; I <256; I ++ ){
If (BUF [I] = '') break;
Else {
Buf1 [J] = Buf [I];
J ++;
}
}
Buf1 [J] = '/0 ';
Fclose (FP );
Gtk_label_set_text (widget, buf1 );
}

11. "swap information" callback function:

Void
On_label53_realize (gtkwidget * widget,
Gpointer user_data)
{
File * FP;
Int I, J;
Char Buf [256], buf1 [256];
Fp = fopen ("/proc/meminfo", "R ");
Fgets (BUF, 256, FP );
Fgets (BUF, 256, FP );
Fgets (BUF, 256, FP );
For (I = 0; I <256; I ++ ){
If (BUF [I] = ':') break;
}
I ++;
For (; I <256; I ++ ){
If (BUF [I]! = '') Break;
}
J = 0;
For (; I <256; I ++ ){
If (BUF [I] = '') break;
Else {
Buf1 [J] = Buf [I];
J ++;
}
}
Buf1 [J] = '/0 ';
Fclose (FP );
Gtk_label_set_text (widget, buf1 );
}

12. "memory usage information" callback function:

Void timeout_label52 (gtkwidget * widget, gpointer user_data)
{
File * FP;
Int I, J;
Char Buf [256], buf1 [256];
Fp = fopen ("/proc/meminfo", "R ");
Fgets (BUF, 256, FP );
Fgets (BUF, 256, FP );
For (I = 0; I <256; I ++ ){
If (BUF [I] = ':') break;
}
I ++;
For (; I <256; I ++ ){
If (BUF [I]! = '') Break;
}
For (; I <256; I ++ ){
If (BUF [I] = '') break;
}
For (; I <256; I ++ ){
If (BUF [I]! = '') Break;
}
J = 0;
For (; I <256; I ++ ){
If (BUF [I] = '') break;
Else {
Buf1 [J] = Buf [I];
J ++;
}
}
Buf1 [J] = '/0 ';
Fclose (FP );
Gtk_label_set_text (widget, buf1 );
}
Void
On_label52_realize (gtkwidget * widget,
Gpointer user_data)
{
Gtk_timeout_add (200, timeout_label52, widget );
}

13. "SWAT usage information" callback function:

Void timeout_label54 (gtkwidget * widget, gpointer user_data)
{
File * FP;
Int I, J;
Char Buf [256], buf1 [256];
Fp = fopen ("/proc/meminfo", "R ");
Fgets (BUF, 256, FP );
Fgets (BUF, 256, FP );
Fgets (BUF, 256, FP );
For (I = 0; I <256; I ++ ){
If (BUF [I] = ':') break;
}
I ++;
For (; I <256; I ++ ){
If (BUF [I]! = '') Break;
}
For (; I <256; I ++ ){
If (BUF [I] = '') break;
}
For (; I <256; I ++ ){
If (BUF [I]! = '') Break;
}
J = 0;
For (; I <256; I ++ ){
If (BUF [I] = '') break;
Else {
Buf1 [J] = Buf [I];
J ++;
}
}
Buf1 [J] = '/0 ';
Fclose (FP );
Gtk_label_set_text (widget, buf1 );
}

Void
On_label54_realize (gtkwidget * widget,
Gpointer user_data)
{
Gtk_timeout_add (200, timeout_label54, widget );
}

14. "process display" function (this function is written in Main. C ):

Void procc_see (gtkwidget * window)
{
Gtkwidget * widget, * view;
Gtktextbuffer * buffer;
File * FP;
Gtktextiter P;
Int I;
Char * Buf = malloc (2048 * sizeof (char ));

Fp = popen ("PS-l-x", "R ");
/* For (I = 0; I <12288; I ++)
{
Fscanf (FP, "% C", & Buf [I]);
If (BUF [I] = '/0') break;
}
View = lookup_widget (window, "textview1 ");
Buffer = gtk_text_buffer_new (null );
Gtk_text_view_set_buffer(Gtk_text_view (view), buffer );
Gtk_text_buffer_set_text (buffer, Buf,-1 );*/

Widget = lookup_widget (window, "textview1 ");
Buffer = gtk_text_view_get_buffer (gtk_text_view (widget ));
Buffer = gtk_text_buffer_new (gtk_text_buffer_get_tag_table (buffer ));
Gtk_text_view_set_buffer(Gtk_text_view (widget), buffer );
G_object_unref (g_object (buffer ));
Gtk_text_buffer_get_end_iter (buffer, & P );
While (I = fread (BUF, 1, sizeof (BUF), FP)> 0 ){
Gerror * err = NULL;
Gsize Br, BW;
Gchar * text;
If (! (Text = g_locale_to_utf8 (BUF, I, & Br, & BW, & ERR ))){
G_printerr ("failed locale to UTF-8 conversion: % s/n", err-> message );
G_clear_error (& ERR );
Break;
}
Gtk_text_buffer_insert (buffer, & P, text, BW );
G_free (text );
}
Pclose (FP );
}

15. "view system type" callback function: it is the same as the callback function in the previous "view system version", except that the file to be used is different.

Do not go into details.

Finally, compile with the command:./autogen. SH and make install.

Note: This process manager provides fewer functions. However, programs written in this mode are easy to expand, mainly for the compilation of callback functions. For more information, see related books or Google!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.