I would like to start a bash script from another bash script, but start it in its own process group just like when you run it from the terminal.
There are a few similar questions, but I can't find an answer that matches my example.
Take these two scripts
$ cat main.sh #! /usr/bin/env bash set -e echo if this has been started in its own group the following will pass ps -o ppid,pgid,command $$ ps -o pgid | grep $$ echo passed $ cat wrapper.sh #! /usr/bin/env bash set -e ./main.sh
When I run
main.sh on its own, the terminal puts it in its own group:
$ ./main.sh if this has been started in its own group the following will pass PPID PGID COMMAND 20553 1276 bash ./main.sh 1276 1276 1276 passed $ echo $? 0
but when I run
wrapper.sh my test fails
$ ./wrapper.sh if this has been started in its own group the following will pass PPID PGID COMMAND 2224 2224 bash ./main.sh $ echo $? 1
But what do I have to put into either
main.sh to make it run
main.sh in its own group the same way it would if it does when it is run straight from the terminal?
(If it makes a difference, I am actually hoping to run
./main.sh & in
wrapper.sh but it was easier to run it in the foreground for this experiment.)
(I am using ubuntu 18)