2024-05-14 13:07:51 发布
网友
操作系统是否可以看到CPython中的调用堆栈(例如函数之间的调用)?例如,操作系统以何种方式参与Python堆栈的创建、检索和/或管理及其stack frames的操作
背景:
ulimit
In what way is the OS involved in the creation, retrieval and/or management of the Python stack and operations of its stack frames?
事实并非如此。堆栈帧由进程处理,内核不会干扰
My understanding is that the Python interpreter does not support tail call recursion, so this seems to be something left to Python to handle.
是的,Python的工作是处理自己的堆栈,而不管尾部递归。Python不支持尾部递归这一事实对于深度递归调用可能有一些缺点,但是代码总是可以被重写为迭代的
另见:What is the maximum recursion depth in Python, and how to increase it?
the kernel clearly can get involved in at least limiting the size of the call stack
是的,内核确实限制了堆栈的大小。方法是在堆栈顶部之后分配一个不可见的保护页:当堆栈已满时,进行另一个调用(从而添加另一个堆栈帧)将触发对保护页的读取和/或写入,内核将检测到它并增加堆栈大小。但是,这只会在达到某个预定义量时发生,之后进程将因超过允许的最大堆栈大小而终止
另见:Stack memory management in Linux
事实并非如此。堆栈帧由进程处理,内核不会干扰
是的,Python的工作是处理自己的堆栈,而不管尾部递归。Python不支持尾部递归这一事实对于深度递归调用可能有一些缺点,但是代码总是可以被重写为迭代的
另见:What is the maximum recursion depth in Python, and how to increase it?
是的,内核确实限制了堆栈的大小。方法是在堆栈顶部之后分配一个不可见的保护页:当堆栈已满时,进行另一个调用(从而添加另一个堆栈帧)将触发对保护页的读取和/或写入,内核将检测到它并增加堆栈大小。但是,这只会在达到某个预定义量时发生,之后进程将因超过允许的最大堆栈大小而终止
另见:Stack memory management in Linux
相关问题 更多 >
编程相关推荐