When using the following command from an interactive shell:

bash -c "sleep 1001 & sleep 1002 & set -m; sleep 1003"

the sleep 1003 command ends up in its own process group, which also includes 
the other two sleep commands.

    PID    PPID    PGRP     SID CMD
 190870   12953  190870  190870     bash
 193199  190870  193199  190870       sleep 1003
 193200  193199  193199  190870         sleep 1001
 193201  193199  193199  190870         sleep 1002

This does not look as satisfying the description of "set -m" for "sleep 1003": "All 
processes run in a separate process group."

It seems that the fork optimisation would have been correct (reusing the 
shell's own process group obtained from the interactive shell)
if no other processes were in that process group (which might be difficult to 
check if sub-processes in the same process group
would not be direct shell's children).  It might be possible to create examples of 
commands preceding "set -m" that could
create such detached processes and leave the shell's own process group 
unsuitable for the fork optimisation later.

From GNU bash, version 5.1.8(1)-release (x86_64-redhat-linux-gnu) on RHEL 9.
--
Daniel Villeneuve



Reply via email to