Here is the first assignment of CS703 for Spring Semester 2018. It is an old assignment. Its main objective is to urge students to install Ubunu or Linux on their system and learn how to run and exececute C/c++ program. Ubuntu can be installed in Windows environment with the help of any Virtual machine/Box. Or you may try to install in sepratly on a partition. More assignment in this semester might be Ubuntu or Linux based. Hence I would recommend you to install Ubuntu or Linux in your system.
CS703 Assignment No 1 Spring 2018
Develop an application in C language which will run in Linux operating systems to display the following properties of the system:
§ Vendor of the Processor (5 marks)
§ Ram size (5 marks)
§ Computer name (5 marks)
§ System time (5 marks)
§ Version of operating system’s kernel (5 marks)
With source code of the application, screen-shots after running this application are also required. (5 marks)
S703 Assignment No 1 Spring 2018 Solution IDEA or Guideline
CS703 Assignment No 1 Spring 2018 Solution file….
Change accordingly and run it on Ubuntu …
Install Ubuntu as VM or on Separate Partition as secondary OS….
Then watch tutorial how to compile and run C program in CMD Shell
..Take snapshot and zip the code and snapshot …
Develop an application in C language which will run in Linux operating systems to display the following properties of the system:
§ Vendor of the Processor (5 marks)
§ Ram size (5 marks)
§ Computer name (5 marks)
§ System time (5 marks)
§ Version of operating system’s kernel (5 marks)
With source code of the application, screen-shots after running this application are also required. (5 marks)
Solution:
Program:
#include <sys/sysctl.h>
#include <sys/types.h>
#include<sys/utsname.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
void getRAMSize()
{
FILE *meminfo = fopen(“/proc/meminfo”, “r”);
int totalMemory = 0;
if(meminfo == NULL)
{
exit(-1);
}
char buff[256];
while(fgets(buff, sizeof(buff), meminfo))
{
int ramKB;
if(sscanf(buff, “MemTotal : %d kB”, &ramKB) == 1)
{
totalMemory = ramKB;
}
}
if(fclose(meminfo) != 0)
{
exit(-1);
}
printf(“RAM Size : %d KB\n”, totalMemory);
}
void getComputerName()
{
int ret;
struct utsname buf;
ret = uname(&buf);
if(!ret) {
printf(“Computer name : %s\n”,buf.nodename);
}
}
void getKernelVersion()
{
int ret;
struct utsname buf;
ret = uname(&buf);
if(!ret) {
printf(“Kernel Version : %s\n”, buf.release);
}
}
void getSystemTime()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( “Current system time and date : %s”, asctime (timeinfo) );
}
void getProcessorVendor()
{
char cmd[100];
sprintf(cmd, “cat /proc/cpuinfo | grep vendor | uniq”);
system(cmd);
}
void main()
{
printf(“****************************\nSolution Assignment: 01 (CS703)\nID: MS160400843\nName: Muhammad Shahid Azeem\n****************************\n\n”);
getProcessorVendor();
getRAMSize();
getComputerName();
getSystemTime();
getKernelVersion();
}