os.system('exit') 在 python 中

Vas*_*pov 2 python terminal process exit terminate

我的朋友在 macOS 环境中,他想os.system('exit')在他的 python 脚本末尾调用以关闭终端。它没有。这并不让我感到惊讶,但我想知道在进行此调用时 python 脚本和终端之间究竟发生了什么

在我的心理模拟中,终端应该告诉你还有正在运行的作业,但这也不会发生。

作为一个附带问题:当进程调用它时,一些不太常见的终端会关闭吗?

Foo*_*Bah 5

阅读帮助:

Execute the command (a string) in a subshell.
Run Code Online (Sandbox Code Playgroud)

启动一个子shell,并exit在该子shell中运行。

要退出封闭终端,您必须杀死父级。一种方法是:

os.system("kill -9 %d"%(os.getppid())
Run Code Online (Sandbox Code Playgroud)

  • 只需添加一个括号:`os.system("kill -9 %d"%(os.getppid()))` (2认同)