Hello Ganael. Ganael Laplanche wrote in <2616938.TYJnH3iKXO@xxxxxxxxxxxxxxxxx>: |On Friday, January 13, 2023 10:03:35 PM CET Steffen Nurpmeso wrote: |> Well i mean, in spirit of Wheeler's "anything is possible with |> (one more) indirection" it could be possible nonetheless? ... |It is not clear for me why that extra fork fixes the problem, but it \ |works, |thanks! | |Unfortunately, my initial goal is to get a new process group for later |children processes, but FreeBSD's sh (as well as dash) requires 'set \ |-m' to be |executed from the first process [1]. The extra fork breaks that requirem\ |ent. |The following example shows that the new process' PGID remains the \ |same as the |initial shell: | |$ cat test_pgid.sh |( | set -m | ( | sleep 1 | ) & | i=$! | echo "Main shell has: $(ps -o pid,pgid $$)" | echo "Sub-shell has: $(ps -o pid,pgid $i)" | wait $i |) |$ dash test_pgid.sh & |Main shell has: PID PGID |10362 10362 |Sub-shell has: PID PGID |10364 10362 |[1] + done dash test_pgid.sh | |So I am afraid the 'extra fork' tip is not useable for me... Thanks for this information, that i did not expect. Indeed .. it seems no new process group is used for the child shell. That thoroughly i have not looked. ... |[1] Discussed here: https://lists.freebsd.org/archives/freebsd-hackers/2\ |022-March/000924.html Very interesting. With the correction (fwiw) that * with bash, it hangs (as expected with a new process group) is not true with bash 5.2.15 on Linux 6.1 with glibc $ bash -c '(set -m; echo "echo from background" & wait "$!"); echo "wait returns $?"' echo from background [1]+ Done echo "echo from background" wait returns 0 (Well the following "hangs" in that it does not print a prompt) $ bash -c '(set -m; echo "echo from background $$" & echo $!; wait "$!"); echo "wait returns $?"' & [1] 21123 #?0|kent:nail.git$ 21125 echo from background 21123 [1]+ Done echo "echo from background $$" wait returns 0 So i think i am out of ideas except doing what Jilles suggested in the message, enwrapping the inner thing with sh -c '..'. And that seems to work a bit as #!/bin/dash #( sh -c ' set -m ( sleep 1 ) & i=$! echo >&2 "inner Main shell has: $(ps -o pid,pgid $$)" echo >&2 "inner Sub-shell has: $(ps -o pid,pgid $i)" wait $i ' </dev/null >/dev/null & echo "Main shell has: $(ps -o pid,pgid $$)" #) echo "outer Main shell has: $(ps -o pid,pgid $$)" ends up as #?148|kent:tmp$ ./t.sh Main shell has: PID PGID 22300 22300 inner Main shell has: PID PGID 22301 22301 outer Main shell has: PID PGID 22300 22300 #?0|kent:tmp$ inner Sub-shell has: PID PGID 22303 22303 sh: 9: Cannot set tty process group (No such process) logout There are stopped jobs. Ciao! --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)