LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-14-2013, 04:19 PM   #1
mattmc
LQ Newbie
 
Registered: Oct 2013
Location: Ann Arbor, MI
Distribution: RedHat 6.4
Posts: 2

Rep: Reputation: Disabled
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.

Last edited by mattmc; 10-14-2013 at 08:14 PM.
 
Old 10-14-2013, 04:55 PM   #2
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
Quote:
Originally Posted by mattmc View Post
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
 
Old 10-14-2013, 05:26 PM   #3
mattmc
LQ Newbie
 
Registered: Oct 2013
Location: Ann Arbor, MI
Distribution: RedHat 6.4
Posts: 2

Original Poster
Rep: Reputation: Disabled
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

Last edited by mattmc; 10-14-2013 at 08:15 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
req: Bash Script check if process command is running if not run it >> skate Linux - Software 3 12-17-2012 02:13 AM
My BASH script work perfect when i run it manualy, but not when it run in the crontab roqarg Linux - Newbie 30 05-06-2010 01:37 PM
bash script: compare two group list Dr_Death_UAE Linux - General 7 09-03-2009 07:32 AM
bash script user group folder zerocool22 Programming 6 05-27-2008 06:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration