Monitoring the process execution and memory consumption in its lifetime

*/-->

Monitoring the process execution and memory consumption in its lifetime

Recently, I am working on a research project which involves the monitoring of
some processes, I want to get the output of the top command for further
analysis, the shell script to do this is as follows:

 1: #!/bin/bash
 2:
 3: mem_load_file=/tmp/mem_load
 4: for exe in `find ./bin -type f`
 5: do
 6: 	echo $exe >> $mem_load_file
 7: 	./$exe &
 8: 	bgpid=$!
 9: 	echo $bgpid >> $mem_load_file
10: 	top | grep $bgpid >> $mem_load_file &
11: 	wait $bgpid
12: 	killall top
13: done

The mechanism behind this script is to start the process as a background process
(line 7) and get its pid (line 8), the pid is used for top and grep, and it
is important to make the top command background so that the monitoring can go
all the way till the target process exit. The wait call at line 11 makes sure
that the process terminate. Then the top can be killed.

The output looks like:

 1: ./bin/sp.W
 2: 861
 3:   861 wujing    20   0   23656   9528    840 R 98.16 0.118   0:00.15 sp.W
 4:     1 root      20   0   48616   1696    476 S 0.000 0.021   0:00.62 systemd
 5:   861 wujing    20   0   23656   9528    840 R 99.43 0.118   0:03.14 sp.W
 6:     1 root      20   0   48616   1696    476 S 0.000 0.021   0:00.62 systemd
 7: ./bin/cg.W
 8: 865
 9:   865 wujing    20   0   22716   8540    808 R 84.60 0.106   0:00.13 cg.W
10: ./bin/is.B
11: 869
12:   869 wujing    20   0  274640   8512    256 R 98.21 0.105   0:00.15 is.B
13:   869 wujing    20   0  274640 120956    412 R 99.48 1.497   0:03.14 is.B
14: ./bin/lu.C
15: 873
16:   873 wujing    20   0  608760 139080    776 R 91.72 1.722   0:00.14 lu.C
17:   873 wujing    20   0  608760 592104    788 R 99.15 7.329   0:03.12 lu.C
18:   873 wujing    20   0  608760 593160    812 R 99.47 7.342   0:06.11 lu.C
19:   873 wujing    20   0  608760 593160    812 R 99.45 7.342   0:09.10 lu.C
20:   873 wujing    20   0  608760 593160    812 R 99.13 7.342   0:12.08 lu.C
21:   873 wujing    20   0  608760 593160    812 R 99.46 7.342   0:15.07 lu.C
22:   873 wujing    20   0  608760 593160    812 R 99.42 7.342   0:18.06 lu.C
23:   873 wujing    20   0  608760 593160    812 R 99.10 7.342   0:21.04 lu.C
24:   873 wujing    20   0  608760 593160    812 R 99.45 7.342   0:24.03 lu.C
25:   873 wujing    20   0  608760 593160    812 R 99.15 7.342   0:27.01 lu.C
26:   873 wujing    20   0  608760 593160    812 R 99.46 7.342   0:30.00 lu.C
27:   873 wujing    20   0  608760 593160    812 R 99.15 7.342   0:32.98 lu.C
28:   873 wujing    20   0  608760 593160    812 R 99.48 7.342   0:35.97 lu.C
29:   873 wujing    20   0  608760 593160    812 R 99.15 7.342   0:38.95 lu.C
30:   873 wujing    20   0  608760 593160    812 R 99.45 7.342   0:41.94 lu.C
31:   873 wujing    20   0  608760 593160    812 R 99.13 7.342   0:44.92 lu.C
32:   873 wujing    20   0  608760 593160    812 R 99.46 7.342   0:47.91 lu.C
33:   873 wujing    20   0  608760 593160    812 R 99.13 7.342   0:50.89 lu.C
34:   873 wujing    20   0  608760 593160    812 R 99.46 7.342   0:53.88 lu.C
35:   873 wujing    20   0  608760 593160    812 R 99.12 7.342   0:56.86 lu.C
36:   873 wujing    20   0  608760 593160    812 R 99.13 7.342   0:59.84 lu.C
37:   873 wujing    20   0  608760 593160    812 R 99.48 7.342   1:02.83 lu.C
38:   873 wujing    20   0  608760 593160    812 R 99.13 7.342   1:05.81 lu.C
39:   873 wujing    20   0  608760 593160    812 R 99.47 7.342   1:08.80 lu.C
40:   873 wujing    20   0  608760 593160    812 R 99.13 7.342   1:11.78 lu.C
41:   873 wujing    20   0  608760 593160    812 R 99.14 7.342   1:14.76 lu.C
42:   873 wujing    20   0  608760 593160    812 R 99.48 7.342   1:17.75 lu.C
43:   873 wujing    20   0  608760 593160    812 R 99.14 7.342   1:20.73 lu.C
44:   873 wujing    20   0  608760 593160    812 R 99.45 7.342   1:23.72 lu.C
45:   873 wujing    20   0  608760 593160    812 R 99.15 7.342   1:26.70 lu.C
46:   873 wujing    20   0  608760 593160    812 R 99.15 7.342   1:29.68 lu.C
47:   873 wujing    20   0  608760 593160    812 R 99.48 7.342   1:32.67 lu.C
48:   873 wujing    20   0  608760 593160    812 R 99.15 7.342   1:35.65 lu.C
49:   873 wujing    20   0  608760 593160    812 R 99.47 7.342   1:38.64 lu.C
50:   873 wujing    20   0  608760 593160    812 R 99.14 7.342   1:41.62 lu.C

Author: wujing

Created: 2014-09-16 二 10:08

Emacs 24.3.1 (Org mode 8.2.6)

Validate

时间: 2024-07-29 03:17:28

Monitoring the process execution and memory consumption in its lifetime的相关文章

System and method for parallel execution of memory transactions using multiple memory models, including SSO, TSO, PSO and RMO

A data processor supports the use of multiple memory models by computer programs. At a device external to a data processor, such as a memory controller, memory transactions requests are received from the data processor. Each memory transaction reques

prototype linkage can reduce object initialization time and memory consumption

//对象是可变的键控集合, //“numbers, strings, booleans (true and false), null, and undefined” 不是对象的解释 The simple types of JavaScript are numbers, strings, booleans (true and false), null, and undefined. All other values are objects. Numbers, strings, and boolea

nodejs内存溢出 FATAL ERROR: CALL_AND_RETRY_0 Allocation failed – process out of memory

spa项目整体迁移转为ssr后,改动之后部署一切还好,就是突然有一天访问人数太多,node进程很容易就挂了自动重启. 最后经过压力测试,考虑到是堆内存溢出的问题,就报错误:FATAL ERROR: CALL_AND_RETRY_0 Allocation failed – process out of memory 1.复现结果: 采用Jmeter做压力测试,1s50次,持续请求,观察node进程占用内存情况 经过观察发现持续请求,node进程占用内存一直升高,最后达到1.4G左右,就不会再升,因

C++ Measures CPU and memory consumption

We all know monitor, just as Windows Task Manager,can measure cpu used and memory cost. Now I record that today I studied.Firstly,shell goes first.-------Command 1-------#shell begin here#!/bin/ksh## Returns total memory used by process $1 in kb.## S

【转载】GetAdaptersInfo函数在64位系统上返回ERROR_NOACCESS的有关问题

From:http://www.educity.cn/wenda/351190.html GetAdaptersInfo函数在64位系统下返回ERROR_NOACCESS的问题 实际应用中一个程序在长时间运行后内存占用较高时发生崩溃,从dump信息中,发现GetAdaptersInfo函数返回了一个奇怪的错误码998(ERROR_NOACCESS),百度搜索不到相关的信息.MSDN上GetAdaptersInfo函数的错误码正常情况下只有5种.并且一共发生的两次崩溃都出现在一台Win7 64位机

1301 - Monitoring Processes

   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 MB We have planned to design a new operating system. Like other OS we will use the techniques of processes, schedulers, locks etc. The basic plan is to use the OS in hardwires

PatentTips - Scheduling compute kernel workgroups to heterogeneous processors based on historical processor execution times and utilizations

BACKGROUND OF THE INVENTION? 1. Field of the Invention? The present invention relates generally to heterogeneous computer systems.? 2. Background Art? Computers and other such data processing devices have at least one control processor that is genera

How to detect and avoid memory and resources leaks in .NET applications

Despite what a lot of people believe, it's easy to introduce memory and resources leaks in .NET applications. The Garbage Collector, or GC for close friends, is not a magician who would completely relieve you from taking care of your memory and resou

Virtualizing memory type

A processor, capable of operation in a host machine, including?memory management logic to support a plurality of?memory?types for a physical?memory access by the processor, and virtualization support logic to determine a host memory?type?for a refere