我正在学习安全挑战。其中一项挑战要求我检索已被破坏并保存在内存中直到垃圾收集器触发的数据。
我尝试了很多东西。我想知道是否可以从 python 控制台转储进程内存。
另外,挑战给了我们一个python控制台,但是有一个秒表而不是“>>>”。他们怎么能做那样的事? 我只有一个可以启动 python 控制台的 ssh 访问权限。
谢谢
最佳答案
您可以使用下面的代码查看垃圾中有什么。
import gc
def dump_garbage():
"""
show us what's the garbage about
"""
# force collection
print("\nGARBAGE:")
gc.collect()
print("\nGARBAGE OBJECTS:")
for x in gc.garbage:
s = str(x)
if len(s) > 80: s = s[:80]
print(type(x),"\n ", s)
if __name__=="__main__":
import gc
gc.enable()
gc.set_debug(gc.DEBUG_LEAK)
# make a leak
l = []
l.append(l)
del l
# show the dirt ;-)
dump_garbage()
关于python - 我如何查看垃圾收集器中的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45734315/