English 中文(简体)
如何使许多身患高射弹的儿童完全了解这一进程?
原标题:How to get the total memory of a process which fork many children in linux with shell?

http://www.un.org。

I use africagrep http://europa.rep-v grep:

USER     PID     RSS   COMMAND
root     14347   3220  /usr/sbin/httpd
apache   14348   2400  /usr/sbin/httpd
apache   14349   2400  /usr/sbin/httpd
apache   14350   2400  /usr/sbin/httpd

我可以简单地积累RSS的田地,以获得[http://www.d]的全部记忆。 3220+2400+2400+2400 = 10420

但我知道,儿童进程已分享记忆。 这里有一些多余的计算方法。 实际上,记忆使用的总规模可能低于10420。

我的问题是如何实际利用记忆。

问题回答

如果你需要获得实际记忆,那么你需要把记忆放在Valgrind这样的简介中。

参考

http://kratos-wiki.cimne.upc.edu/index.php/Checking_memory_use_with_Valgrind

Valgrind is probably your most exact choice, but can be a bit awkward to use, and is not reasonable for a production system because of performance (virtually none).

Smem (homepage) (manpage) is a less complicated alternative. PSS process set size is what you re looking for.

我使用了以下指挥系统:

ps aux | grep chrome | grep -v grep | awk  {s+=$5} END {print s} 

请注意,5美元实际上可能有所不同,取决于<代码>ps aux <>code> /code> 实际显示其产出。 这可能对你有用,也可能不有用,也显示用药的总使用量。

I m looking for this answer as well. I ve already found one which works. That is running the service in a container like Docker. Then use docker container stats $containerid

Example:

CONTAINER ID   NAME             CPU %     MEM USAGE / LIMIT     MEM %     NET I/O         BLOCK I/O        PIDS
329f402b9f2e   test-apache2-1   0.15%     2.677GiB / 31.01GiB   8.63%     395MB / 159MB   77.9MB / 819kB   21

I m not sure which feature of containers is allowing this. Is it cgroups? Is it namespaces? Is there a lightweight way to do measure memory from multiple processes without requiring something like Docker or LXC?

我确实知道,这里的数字是准确的。 或者至少比把所有记忆从纸上或顶上加在一起更准确。

There are a couple of ways to accomplish what you re asking here. One involves parsing procfs which doesn t require "root" privileges and the other is using the Taskstats (a Netlink interface) which does.

如果你能够利用Generic Netlinksocketsbyex获得最优的间接费用。

I have a working solution using the first solution that parses procfs:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import time


class ShMemMonitorProcess(object):

    def __init__(self, ppid):
        self.ppid = ppid
        # Create a Sub-Class for Thread module
        self.memory = { kB :1024,  mB :1024*1024,  gB :1024*1024*1024}
        self.scrape_procfs
        
    def calculate_memory(self, vmrss):
        memory, size = vmrss.split()
        return int(memory) * self.memory[size]

    @property
    def scrape_procfs(self):
        rss = 0
        child_ps = dict()
        start = time.time()
        while (time.time() - start) < 100:
            for pid in filter(lambda p: p.isdigit(), os.listdir( /proc )):
                try:
                    # open /proc/PID/status but catch as some can be ephemeral
                    with open( /proc/{}/status .format(pid)) as fh:
                        ppid = [i for i in fh.readlines() if i.startswith( PPid )]
                        if not ppid:
                            continue
                        ppid = ppid[0].split( 	 )[1].strip( 
 )
                        if ppid == self.ppid:
                            with open( /proc/{}/status .format(pid)) as fh:
                                vmrss = fh.readlines()
                                vmrss = [i for i in vmrss if i.startswith( VmRSS )]
                            if not vmrss:
                                continue
                            vmrss = vmrss[0].split( 	 )[1].strip( 
 )
                            ps_rss = self.calculate_memory(vmrss)
                            if not child_ps.get(pid):
                                with open( /proc/{}/comm .format(pid)) as fh:
                                    comm = fh.readlines()
                                    print( Found Child Process {}! .format(pid))
                                    print(comm)
                                print( Adding Process to Hash... )
                                child_ps[pid] = ps_rss
                                rss += ps_rss
                                time.sleep(1)
                            else:
                                # re-calculate process memory
                                print( Process was already found running... )
                                print( Re-calculating memory usage... )
                                previous_rss_used = child_ps[pid]
                                if previous_rss_used > ps_rss:
                                    memory_adj = previous_rss_used - ps_rss
                                    rss -= memory_adj
                                elif previous_rss_used <= ps_rss:
                                    memory_adj = ps_rss - previous_rss_used
                                    rss += memory_adj
                                child_ps[pid] = ps_rss
                            print( Bytes....{} .format(rss))
                except FileNotFoundError:
                    continue


if __name__ ==  __main__ :
    # Pass the Process ID through STDIN on calling
    pid = sys.argv[1]
    shmem = ShMemMonitorProcess(pid)

然后,我就与人民民主党一起问,什么进程是“Parent”,什么是你想要找回的RSS总数。

python ./Find_RSS.py 1234
Found Child Process 12541!                                                                                    

22:54:40 [12/222]
[ Privileged Cont
 ]                                                                                                              
Adding Process to Hash...                                                                                                          
Bytes....202661888                                                                                                                 
Found Child Process 12606!                                                                                                         
[ WebExtensions
 ]                                                                                                                
Adding Process to Hash...                                                                                                          
Bytes....667672576                                                                                                                 
Found Child Process 12666!                                                                                                         
[ Utility Process
 ]                                                                                                              
Adding Process to Hash...                                                                                                          
Bytes....709660672                                                                                                                 
Found Child Process 14803!                                                                                                         
[ RDD Process
 ]  




相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签