大虚拟内存大小使用

时间:2015-05-08 09:17:32

标签: ubuntu python-3.x psutil

美好的一天。

我想知道为什么通过使用subprocess.Popen启动新进程并询问psutil.Process.memory_info()虚拟内存大小我得到的超过21兆字节? (在由Popen启动的脚本中,只打印从主脚本传递的stdin读取的数据)

main.py

from subprocess import Popen, PIPE, STDOUT
import sys, psutil, shlex

with Popen(shlex.split('python3 ./test.py'), stdin=PIPE, stdout=PIPE, stderr=STDOUT) as proc:

main_stdin = sys.stdin.read()
print('Writting main STDIN stream:', main_stdin)
proc.stdin.write(bytes(main_stdin, 'UTF-8')) # "redirect" main's stdin to test's stdin

mem_info = psutil.Process(proc.pid).memory_info()
print('RSS:', mem_info.rss/1048576) # bytes to megabytes
print('VMS:', mem_info.vms/1048576)

sub_stdout = proc.communicate()[0].decode('UTF-8')
print('Reading sub STDOUT: ', sub_stdout)

test.py

from sys import stdin

print(stdin.read())

Ubuntu 14.04,Python 3.4

谢谢!

0 个答案:

没有答案