0

I am writting a bash script first.sh in which I am required to run another scrip second.sh as a daemon.

In order to do so it must be launched from a new bash instance using nohup, so when the bash instance ends second.sh will be adopted by systemd.

How can it be implemented? Is there a way that the next bash instances launched from first.sh will have a different pgid than the one of second.sh?

bash -c 'nohup second.sh &'>/dev/null When new bash instances are launched, the first one shares the pgid of second.sh, is there a way to avoid it?

1 Answers1

0

In bash, use set -m on, new processes will be spawned in a new process group:

(set -m; exec new_process_in_new_group)

You can also use setsid but this starts a new session, which includes a new process group amongst others.

Uriel
  • 182
  • 3
  • 10