美文网首页
linux下应用程序/proc/pid/maps文件python

linux下应用程序/proc/pid/maps文件python

作者: 车到山前必有路2021 | 来源:发表于2020-06-22 15:29 被阅读0次

    #coding:utf-8

    __author__ = 'zhangxd18'

    import sys

    import os

    import string

    if "__main__" == __name__:

        if sys.argv < 2:

            sys.exit(-1)

        map_file = sys.argv[1]

        total_size = 0

        with open(map_file) as f:

            lines = f.readlines()

            for i, line in enumerate(lines):

                tmp_data = line.split("-", 2)

                start_str = tmp_data[0]

                end_str = tmp_data[1].split(" ", 2)[0]

                start = string.atoi("0x" + start_str, 0)

                end = string.atoi("0x" + end_str, 0)

                #size = long(start, 0) - long(end, 0)

                size = end - start

                total_size = total_size + size

                print line

                print "-------- 0x%x 0x%x, %d Byte, %f KB, %f MB\n\n"%(start, end, size, size/1024.0, size/1024.0/1024.0)

            print ("total_size %d Byte, %f KB, %f MB\n\n"%(total_size, total_size/1024.0, total_size/1024.0/1024.0))

    相关文章

      网友评论

          本文标题:linux下应用程序/proc/pid/maps文件python

          本文链接:https://www.haomeiwen.com/subject/cunxfktx.html