LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   need bash script to always run under new process group (https://www.linuxquestions.org/questions/programming-9/need-bash-script-to-always-run-under-new-process-group-4175480768/)

mattmc 10-14-2013 04:19 PM

need bash script to always run under new process group
 
Is there a way to have a bash script know it should always run with a unique pgid? Put another way, I want the bash script to set within itself a new pgid, and pass the 'new' pgid to all it's children.

Now, sure, I could could just write a wrapper script;

Code:

  cat /bin/myscript.newpgid
  #!/bin/bash
  setsid /bin/myscript

But if something non-interactive ran /bin/script, it wouldn't get a new pgid.

From the manpages, I would have thought "#!/bin/bash -m" would have done this, but in my testing it did not (RedHat 6.4). Plus, running a non-interactive script with "-m" is just gross....

-- Peace.

Robhogg 10-14-2013 04:55 PM

Quote:

Originally Posted by mattmc (Post 5045669)
Now, sure, I could could just write a wrapper script... But if something non-interactive ran /bin/script, it wouldn't get a new pgid.

How about setting an environment variable in the wrapper script, and check for that when the script is launched:
Code:

if [ "$WRAPPER_SCRIPT_NAME" != "something_or_other" ]; then
    logger "Not started correctly"
    exit 1
fi


mattmc 10-14-2013 05:26 PM

Hm, that would work in our environment, but this script is used other places where it's re-named. The script even sets "local PROGNAME=$0", and then uses that in functions (as in, exclude the script from ps output).

It would be really cool if this worked;

Code:

  #!/bin/bash
  setsid $$

But it doesn't :(


All times are GMT -5. The time now is 10:10 AM.