Monitoring the process execution and memory consumption in its lifetime

<?xml version="1.0" encoding="utf-8"?> 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

轉載于:https://www.cnblogs.com/wujingcqu/p/3974304.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/375622.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/375622.shtml
英文地址,請注明出處:http://en.pswp.cn/news/375622.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

設置和清除LD_LIBRARY_PATH

"" 設置 export LD_LIBRARY_PATH$LD_LIBRARY_PATH:/the/path/you/want/setexport LD_LIBRARY_PATH/the/path/you/want/set "" 查看設置 echo $LD_LIBRARY_PATH "" 清除 unset LD_LIBRARY_PATH

Jenkins中切換devtoolset

source /opt/rh/devtoolset-4/enable or source scl_source enable devtoolset-4

告訴一個遠程團隊協作的故事

Lisette Sutherland和Elinor Slomba在一起收集一些人的故事&#xff0c;這些人的業務模式須要依靠遠程團隊正確完畢工作。故事中體現出遠程團隊怎樣協作。怎樣跨越距離的障礙&#xff0c;怎樣建立信任&#xff0c;怎樣完畢任務。即將出版的《高能協作&#xff1a;遠程戰地指南》…

混沌數學之呂陳吸引子

呂陳吸引子&#xff08;Lu Chen attractor&#xff09;也稱Lu attractor 吸引子是2002年中國科學院數學與系統科學研究院研究員 呂金虎&#xff08;Jinhu Lu)&#xff0c;Suchun Zhang 和香港城市大學電子工程系講座教授陳關榮&#xff08; Guangrong Chen &#xff09;發現和分…

整數反轉

給出一個 32 位的有符號整數&#xff0c;你需要將這個整數中每位上的數字進行反轉。 示例 1: 輸入: 123 輸出: 321示例 2: 輸入: -123 輸出: -321示例 3: 輸入: 120 輸出: 21注意: 假設我們的環境只能存儲得下 32 位的有符號整數&#xff0c;則其數值范圍為 [?231, 231 ?…

C# char[]與string之間的相互轉換

string 兌換 Char[] string ss "abcdefg";char[] cc ss.ToCharArray();Char[] 轉換成string string s new string(cc);byte[] 與 string 之間的轉換 byte[] bb Encoding.UTF8.GetBytes(ss);string s Encoding.UTF8.GetString(bb);string[] 轉換成string string …

java 直接 訪問WebSphere JNDI

代碼如下: Hashtable<String, String> env new Hashtable<String, String>();env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");env.put(Context.PROVIDER_URL, "iiop://localhost:2809");Co…

Standard C++ Episode 7

六、C的I/O流庫 C&#xff1a;fopen/fclose/fread/fwrite/fprintf/fscanf/fseek/ftell... C&#xff1a;對基本的I/O操作做了類的封裝&#xff0c;其功能沒有任何差別&#xff0c;用法和C的I/O流也非常近似。 七、格式化I/O <</>> 1 /*2 *格式化I/O練習3 */4 #in…

在Android設備與Mac電腦之間傳輸文件

不同于Windows和Linux&#xff0c;Android設備連接到Mac電腦上是看不見掛載的目錄的&#xff0c;既然看不到了Android設備的掛載目錄&#xff0c;如何在Android設備與Mac電腦之間傳輸文件呢&#xff1f; 原來Android官方提供了傳輸文件的工具&#xff01;訪問www.android.com/f…

mysql語句在node.js中的寫法

總結一下mysql語句在node.js中的各種寫法&#xff0c;參考了npm網站mysql模塊給的實例。 查詢 select //1 db.query(select * from tuanshang_users where user_id < 10,function(err,results,fields){//if(err) throw err;console.log( results );if(!!results.length){con…

jqPlot圖表插件學習之折線圖-散點圖-series屬性

一、準備工作 首先我們需要到官網下載所需的文件&#xff1a; 官網下載&#xff08;筆者選擇的是jquery.jqplot.1.0.8r1250.zip這個版本&#xff09; 然后讀者需要根據自己的情況新建一個項目并且按照如下的方式加載對應的js和css&#xff08;因為筆者在VS2012環境下新建的&…

node.js基礎:數據存儲

無服務器的數據存儲 內存存儲 var http require(http); var count 0; //服務器訪問次數存儲在內存中 http.createServer(function(req,res){res.write(hello count);res.end(); }).listen(3000);    基于文件的存儲 node.js中主要用fs文件系統模塊來管理文件的存儲。 文件…

CUDA 6.5 VS2013 Win7:創建CUDA項目

運行環境&#xff1a; Win7VS2013CUDA6.5 1.創建win32空項目 2.右鍵項目解決方案-->生成項目依賴項-->生成自定義 3.右鍵項目解決方案-->屬性-->配置屬性-->常規-->平臺工具集 配置屬性-->VC目錄-->包含目錄&#xff0c;添加 $(CUDA_INC_PATH) 連接器-…

c/c++編碼規范(2)--作用域

2. 作用域 靜止使用class類型的靜態或全局變量。 6. 命名約定 6.1. 函數名&#xff0c;變量名&#xff0c;文件名要有描述性&#xff0c;少用縮寫。 6.2. 文件命名 6.2.1. 文件名要全部用小寫。可使用“_”或"-"&#xff0c;遵從項目規范&#xff0c;沒有規范&#x…

subversion svnserver服務啟動與配置

svnserve 是一個輕量級的服務&#xff0c; 使用自定義的協議通過TCP/IP與客戶端通訊。 客戶端通過由 svn:// 或者 svnssh:// 開始的URL訪問svnserve服務器。 啟動服務器 端口監控&#xff08;inetd&#xff09;模式 如果你打算用端口監控來啟動處理客戶的訪問請求的進程&#x…

mongodb地理空間索引原理閱讀摘要

http://www.cnblogs.com/taoweiji/p/3710495.html 具體原理在上面 簡單概述&#xff0c;&#xff08;x,y&#xff09;經緯度坐標&#xff0c;通過geohash的方式&#xff0c;通過N次方塊四分割生成一個坐標碼&#xff0c;然后用坐標碼進行BTREE的索引建立轉載于:https://www.cnb…

angular 頁面加載時可以調用 函數處理

轉載于 作者:海底蒼鷹地址:http://blog.51yip.com/jsjquery/1599.html 我希望頁面加載的時候&#xff0c;我能馬上處理頁面的數據&#xff0c;如請求API .... 所以這樣設置 在某個頁面的控制器中 監聽頁面load phonecatControllers.controller(registerctr, [$scope, $routePa…

刪除排序數組中的重復項

給定一個排序數組&#xff0c;你需要在原地刪除重復出現的元素&#xff0c;使得每個元素只出現一次&#xff0c;返回移除后數組的新長度。 不要使用額外的數組空間&#xff0c;你必須在原地修改輸入數組并在使用 O(1) 額外空間的條件下完成。 示例 1: 給定數組 nums [1,1,2…

android 處理鼠標滾輪事件 【轉】

android處理鼠標滾輪事件&#xff0c;并不是如下函數&#xff1a; 1&#xff09; public boolean onKeyDown(int keyCode, KeyEvent event) 2) public boolean dispatchKeyEvent(KeyEvent event) 3) public boolean onTouchEvent(MotionEvent event) 而是如下函數 …

ASP.NET數據報表之柱狀圖 ------工作日志

#region 柱形色調 /// <summary> /// 柱形色調 /// </summary> private string[] myColor new string[] { "DarkGreen", "DimGray", "DodgerBlue", "Orchid", //Peru "Orange", "Orchid", &q…