All about programming in GNU/LINUX

Menu driven program to Print the System and OS information under GNU/LINUX

/*HACKINTOSH RAO \M/ : CODE RUNS ONLY UNDER GNU/LINUX
  PROGRAM TO PRINT THE CPU , MEMORY AND OS INFORMATION
  SYSTEM CALLS USED : 1.open
                      2.read
                      3.write
*/

#include<sys/types.h>
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
void show(int fd);
int main()
{
    int fd;//filedescriptor

    int choice;
    while(1)
    {
        printf(“\n1.CPU INFORMATION\n2.MEMORY INFORMATION\n3.GNU/LINUX VERSION\n4.EXIT\n”);
        printf(“\nEnter the choice: “);
        scanf(“%d”,&choice);
        switch(choice)
        {
            case 1:fd=open(“/proc/cpuinfo”,O_RDONLY);
                   show(fd);
                   close(fd);
                   break;
            case 2:fd=open(“/proc/meminfo”,O_RDONLY);
                   show(fd);
                   close(fd);
                   break ;
            case 3:fd=open(“/proc/version”,O_RDONLY);
                   show(fd);
                   close(fd);
                   break;
            default:exit(0);
        }
    }

}

void show(int fd)
{
    int toread;
    char block[1024];
    while((toread=read(fd,block,sizeof(block)))>0)
     write(1,block,toread);
    for(toread=1;toread<50;toread++)
     printf(“*”);
    printf(“\n\n”);
    return ;
}

Advertisements

One response

  1. Kewl! working great..

    December 10, 2011 at 6:06 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s