in reply to Re^2: parent process stuck in read(2) on pipe opened to child process using backtick
in thread parent process stuck in read(2) on pipe opened to child process using backtick

... Maybe this is not the right forum for bash/sh but what's the harm in asking :)

Yes, this is not a bash forum, and all in all, bash configuration is a rather complex topic...

Anyhow, the easiest approach would probably be to add a line

trap "kill 0" EXIT

to your a.sh.  This sets up an exit handler which kills the current process group.

Then run a.sh in a new process group (so you avoid killing the calling Perl script, too):

my $x=`exec perl -e "setpgrp; exec '/root/a.sh'"`;

(I'm not aware of any way to create a new process group from within the shell script itself, so I'm using Perl's setpgrp here.)

Replies are listed 'Best First'.
Re^4: parent process stuck in read(2) on pipe opened to child process using backtick
by choroba (Cardinal) on Feb 14, 2012 at 23:13 UTC

      This isn't really what I meant.   Or how would you adapt this in any elegant way so that when put in a.sh, it runs the code in the script itself under a new process group?  (The idea being that you could say my $x=`./a.sh` without creating an extra wrapper script.)

        I am not sure it would work as advertised, but I woudl try something like
        bash -i -c '(HERE GOES THE ORIGINAL CODE OF a.sh) & echo $!'
        Update: The echo would probably mess with the backticks. I should not link to a material I am not so familiar with :-)