我编写了一个C程序,需要获得自己的CPU和内存使用量.所以我写了这样的东西:
system("prs_pid=`ps | grep prs-m1 | awk '{print $1}'` \n top -n1 | grep -m1 $prs_pid | \
awk '{print \"prs_cpu:\" $7 \"\\nprs_mem:\" $6}' >> /stats");
Run Code Online (Sandbox Code Playgroud)
我的应用程序名称是prs,我做了PS并获得了我的进程的pid,然后想要从运行TOP获得CPU使用率.该程序报告它使用2%内存和0%CPU.但是,在cmd上手动运行相同的命令会返回相同的memry用法,但是我可以通过运行top来验证有效的非零CPU.我不明白为什么从系统内部尝试时cpu的使用总是0%?
我是蝙蝠脚本的新手,我正在阅读一个bat文件来设置eclipse的环境,我看到以下内容并没有理解代码.有人可以评论代码并帮助我.
:::::::: Check if the our working directory contains spaces
set working_dir_no_spaces=%working_dir%
set working_dir_no_spaces=%working_dir_no_spaces: =%
:::::::: If we've got a space, then quit here.
if not "%working_dir_no_spaces%"=="%working_dir%" (
echo ------------------------------------------------------------
echo Your directory path contains a space.
echo Try putting this package without a space in the path
echo ------------------------------------------------------------
echo Recommended location is your C drive itself
echo Common mistake is when people put this at their desktop
echo and unfortunately their name has a space :(
echo ------------------------------------------------------------ …Run Code Online (Sandbox Code Playgroud)