Posted: . At: 2:15 PM. This was 11 years ago. Post ID: 6423
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

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

https://github.com/john302/sysinfo.

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
		System information.
System uptime : 0 days, 1:36:48
Total RAM   : 11854.4 MB
Free RAM   : 7545.7 MB
Number of running processes : 757
This system has 4 processors configured and 4 processors available.

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.

		printf("\t\tSystem information.\n");
 
		/* 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);
 
                printf("This system has %d processors configured and %d processors available.\n", get_nprocs_conf(), get_nprocs());

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.