Open magicant opened 1 year ago
Also, this would not be very useful for job-controlled jobs as they can safely be killed by the job ID notation.
Actually, the current shell implementation does not kill jobs safely. Yash sends a signal to the job process group regardless of whether the job processes are still running.
However, the shell cannot be fully correct because of possible descendant processes in the process group. Even if the process group leader has ended, there may be (orphan) processes in the process group which should be signaled. The shell cannot tell whether the process is part of the process group it created or an unrelated process group created by another shell.
(Issue migrated from https://osdn.net/projects/yash/ticket/47669)
cf. https://www.austingroupbugs.net/view.php?id=1585
It might possibly be useful to add an option that makes the kill built-in send a signal only to the shell's direct child processes. It ensures the signal is not sent to an unrelated process that has reused the process ID of a child process of the shell.
Note that it only works for direct children of the shell. The shell cannot detect grandchildren.
Multi-process pipelines will not benefit from this feature as the signal can be sent only to the last component of the pipeline when you pass the expansion of $! to the kill built-in.
Also, this would not be very useful for job-controlled jobs as they can safely be killed by the job ID notation.