newlisp 监控Linux进程 四


如果用man ps查看ps命令,你会看到下面的参数:


       %cpu       %CPU    cpu utilization of the process in "##.#" format. Currently, it is the CPU time used divided by the time the process
                          has been running (cputime/realtime ratio), expressed as a percentage. It will not add up to 100% unless you are
                          lucky. (alias pcpu).

       %mem       %MEM    ratio of the process‘s resident set size  to the physical memory on the machine, expressed as a percentage.
                          (alias pmem).

       args       COMMAND command with all its arguments as a string. Modifications to the arguments may be shown. The output in this column
                          may contain spaces. A process marked <defunct> is partly dead, waiting to be fully destroyed by its parent.
                          Sometimes the process args will be unavailable; when this happens, ps will instead print the executable name in
                          brackets. (alias cmd, command). See also the comm format keyword, the -f option, and the c option.
                          When specified last, this column will extend to the edge of the display. If ps can not determine display width, as
                          when output is redirected (piped) into a file or another command, the output width is undefined (it may be 80,
                          unlimited, determined by the TERM variable, and so on). The COLUMNS environment variable or --cols option may be
                          used to exactly determine the width in this case. The w or -w option may be also be used to adjust width.

       blocked    BLOCKED mask of the blocked signals, see signal(7). According to the width of the field, a 32 or 64-bit mask in hexadecimal
                          format is displayed. (alias sig_block, sigmask).


%cpu 和 %mem就是我需要的。


ps -p <pid> -o %cpu,%mem,cmd



(set ‘pid (exec "pidof data_service_d"))
(set ‘cmd (string "ps -p " (first pid) " -o %cpu,%mem,cmd"))
(println (exec cmd))


root@jstc:/opt/detector# ./process_status.lsp 
("%CPU %MEM CMD" " 0.2  0.3 ./data_service_d ./config.xml")




该帖提出用shift + I来通知top监控站全部cpu核的使用率,而不是单核。

该贴答案指出ps不是最准确的cpu利用率跟踪工具,而应该使用top -p $pid的方式


newlisp 监控Linux进程 四,古老的榕树,