My sysinfo program updated with new code. Even better than before!

Posted: October 12, 2013. At: 2:15 PM. This was 4 years ago. Post ID: 6423

http://www.securitronlinux.com/files/sysinfo.kdevelop-1.0.tar.gz.

This is the link to my newly updated sysinfo program. This has code added using the sysinfo struct. This means that the memory and uptime information that is output is actually readable now. This is what the output of the memory and uptime section looks like now.

homer@deusvult:~/Documents/sysinfo.kdevelop-1.0$ ./sysinfo 2
		Ram & swap information.
Filename				Type		Size	Used	Priority
/dev/sdb2                               partition	12287996	0	-1
/dev/sdb5                               partition	2559996	0	-2
 
System uptime : 0 days, 2:23:45
Total RAM   : 5900.9 MB
Free RAM   : 147.0 MB
Number of running processes : 368

Stackoverflow has been a great help in terms of getting this code to work.

Here is the code section in question. This outputs much more readable output. A great result.

	if (argc > 1 and strncmp(argv[1], "2", BUF) == 0) {
		printf("\t\tRam & swap information.\n");
		kernel("/proc/swaps", 2);
 
		/* This code from:
		 * http://stackoverflow.com/questions/14345937/sysinfo-returns-incorrect-value-for-freeram-even-with-mem-unit
		 */
		/* Conversion constants. */
		const long minute = 60;
		const long hour = minute * 60;
		const long day = hour * 24;
		const double megabyte = 1024 * 1024;
 
		/* Obtain system statistics. */
		struct sysinfo si;
		sysinfo (&si);
 
		/* Summarize interesting values. */
		printf ("System uptime : %ld days, %ld:%02ld:%02ld\n", 
		    si.uptime / day, (si.uptime % day) / hour, 
		    (si.uptime % hour) / minute, si.uptime % minute);
		printf ("Total RAM   : %5.1f MB\n", si.totalram / megabyte);
		printf ("Free RAM   : %5.1f MB\n", si.freeram / megabyte);
		printf ("Number of running processes : %d\n", si.procs);
 
 
	}

No comments have been made. Use this form to start the conversation :)

Leave a Reply