注意:这个问题最初是在这里被问到的,但即使没有找到可接受的答案,赏金时间也已过期.我正在重新询问这个问题,包括原始问题中提供的所有细节.
python脚本使用sched模块每60秒运行一组类函数:
# sc is a sched.scheduler instance
sc.enter(60, 1, self.doChecks, (sc, False))
Run Code Online (Sandbox Code Playgroud)
该脚本使用此处的代码作为守护进程运行.
作为doChecks的一部分调用的许多类方法使用子进程模块来调用系统函数以获取系统统计信息:
ps = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE).communicate()[0]
Run Code Online (Sandbox Code Playgroud)
这可以在整个脚本崩溃之前运行一段时间,并出现以下错误:
File "/home/admin/sd-agent/checks.py", line 436, in getProcesses
File "/usr/lib/python2.4/subprocess.py", line 533, in __init__
File "/usr/lib/python2.4/subprocess.py", line 835, in _get_handles
OSError: [Errno 12] Cannot allocate memory
Run Code Online (Sandbox Code Playgroud)
脚本崩溃后,服务器上的free -m输出为:
$ free -m
total used free shared buffers cached
Mem: 894 345 549 0 0 0
-/+ buffers/cache: 345 549
Swap: 0 …Run Code Online (Sandbox Code Playgroud)