I am trying to learn about the Top process manager for Linux. I am trying to understand how Top gets its memory information. So far I have found some memory code in Top.c and Top.h to display the data but I can't see how exactly is getting its memory information from the Operating System.

Is top using /proc/meminfo or using some kind of system call to get the information?

In Top.c

// Display Memory and Swap stats


if (CHKw(Curwin, View_MEMORY)) {

show_special(0, fmtmk(MEMORY_line1

, kb_main_total, kb_main_used, kb_main_free, kb_main_buffers));

show_special(0, fmtmk(MEMORY_line2

, kb_swap_total, kb_swap_used, kb_swap_free, kb_main_cached));

Msg_row += 2;



#define MEMORY_line1 "Mem: \03" \

" %8luK \02total,\03 %8luK \02used,\03 %8luK \02free,\03 %8luK \02buffers\03\n"
New contributor
Ninja2k is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

put on hold as too broad by G-Man, Mr Shunz, Thomas, msp9011, Archemar 2 days ago

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.