linux - 在unix中,我通过提供ppid来使用kill命令,然后它关闭终端。为什么? kill -9 ppid

标签 linux terminal kill pid

sleep 5000

在一个终端和第二个终端中我正在运行:

ps -ef | grep sleep

然后我使用 ppid 在第二个终端中终止此进程。然后它将关闭我运行 sleep 命令的第一个终端。它不会将 sleep 命令创建为孤儿命令。

$ ps -ef | grep sleep
trainee   4887  4864  0 17:05 pts/0    00:00:00 sleep 5000
trainee   4889  4264  0 17:05 pts/1    00:00:00 grep --color=auto sleep
kill -9 4864

为什么?

最佳答案

大概 sleep 的父级是你的 shell。当您终止时,您的登录将被终止并且您的终端将关闭。

维基百科关于 Orphan process 的文章阅读(部分),

An orphan process is a computer process whose parent process has finished or terminated, though it remains running itself.

A process can be orphaned unintentionally, such as when the parent process terminates or crashes. The process group mechanism in most Unix-like operation systems can be used to help protect against accidental orphaning, where in coordination with the user's shell will try to terminate all the child processes with the SIGHUP process signal, rather than letting them continue to run as orphans.

关于linux - 在unix中,我通过提供ppid来使用kill命令,然后它关闭终端。为什么? kill -9 ppid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27778756/

相关文章:

macos - 复制文件并给它一个不同的名称 mac 终端

linux - 如何正确终止 bash 中的进程

c# - 从 C# 关闭最小化/图标化进程

linux - 在 firefox/linux 上运行 web 测试框架 watir

java - 当我从终端运行 java 程序时缺少属性文件

android - Termux 不能运行c++程序?

java - 检查rabbitMQ中的持久队列是否有数据?

linux - 如何创建和运行安装了相同配置和软件的多个ec2实例?

linux - 桉树启动但出现错误

linux - Linux中/dev/uinput和/dev/input有什么区别?