Re: Forking and subshells - Keeping the parent active



On Sat, 28 Jun 2008 21:30:51 -0500, Bob Bob wrote:

I am finding this hard to find information on..

Running a bash script, that is setup to fork a subshell (also a bash
script)

Want the parent to keep running while the child is doing its processing.

There is a trap in the parent script to make it sleep if the child runs
over time. The communication of this event is a simple "while -f
filename" in the parent that is setup by a "touch filename" at the start
of the child script and a subsequent "rm -f filename" at the end.

Not rocket science or anything!

Within the parent script the fork is simply;

sh childscript

Do:
sh childscript &

to put the childscript into the background. The shell will give you the
job number and PID of the backgrounded task. After the loop you can use
'wait' which will stall the parent script until ALL child instances
finish.

example:

for p in 1 2 3 4 5 6 7 8 9; do
sh childscript $p &
done
wait

echo All done

regards,
Frank Ranner
.



Relevant Pages

  • Re: Questions about perl daemons with child processes and open files / signals
    ... running as daemon which launch a child process. ... I need to run a perl script as a daemon. ... tcpdump output, but I decided to use a pipe ... the parent process. ...
    (comp.lang.perl.misc)
  • pdksh problem : Killing child also kills parent
    ... My problem is that I have a script that runs another ... script (ChildScript) in the background, ... echo "Starting Child $ChildScript" ... echo "Child starting to count to 10" ...
    (comp.unix.shell)
  • Re: ruby wish-list
    ... So my thought would be to have the parent and child share a "freeable" ... My hypothesis is that this would allow for a single script to execute ... [the child could run in the other core]. ...
    (comp.lang.ruby)
  • Re: IO::Pty - reads/writes fail *only* with system()
    ... perl script which forks, the child reopens stdin/stdout on the slave side of the pty, and the parent reopens on the master side. ... The script is short and reproduced below. ...
    (comp.lang.perl.modules)
  • Trying to understand this forking open stuff...
    ... My test script: ... parent starts: Wed Nov 8 13:45:14 2006 ... child starts: Wed Nov 8 13:45:14 2006 ... I expected the first trial print statements to execute in the same ...
    (perl.beginners)