简体   繁体   English

程序中的Linux系统(“ top -p pid”)命令

[英]Linux system(“top -p pid”) command in program

I have a Linux program that is interspersed with calls to the system API, specifically system("top") , so I can monitor virtual memory at various points in the program. 我有一个散布着对系统API(特别是system("top")调用的Linux程序,因此我可以在程序的各个位置监视虚拟内存。 I print the memory stats 4 times, as well as attempting to print other data in between these calls. 我打印了4次内存统计信息,并尝试在这些调用之间打印其他数据。

However, when my program is complete, it looks as if the top command is refreshing the page, so the other data I need to print is being obliterated. 但是,当我的程序完成时,看起来好像top命令正在刷新页面,所以我需要打印的其他数据被删除了。 I tried to add a number of iterations, as in, system("top -p pid -n 1) but I had the same problems. 我尝试添加一些迭代,例如system("top -p pid -n 1)但我遇到了同样的问题。

Is there a way to have a call to top in Linux not refresh the output buffer? 有没有办法在Linux中调用top而不刷新输出缓冲区? I don't know where else to turn. 我不知道该去哪里。 Thanks! 谢谢!

您可以自己在/ proc中打开相关文件,并根据需要显示信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM