04-27-2009
background processing in BASH
I have script 3 scripts 1 parent (p1) and 2 children child1 and child2
I have script 3 scripts
1 parent
2 children
child1
child2
In the code below the 2 child processes fire almost Instantaneously in
the background, Is that possible to know the status of pass/fail of each
process "as it happens" ?
In the present scenario although Child2 failed first ( exit 1 ) the status is not displayed until Child1 is complete.
I would really apprecitate your help.
Mother Process:
--------------------------------------
#!/bin/bash
echo -e " Parent continued process 1"
echo -e " Parent continued process 2"
echo -e " ** Kicking off a child process C1** "
./child1 &
t1=$!
echo -e " Parent continued process 3"
echo -e " Parent continued process 4"
echo -e " ** Kicking off a child process C2** "
./child2 &
t2=$!
wait $t1
if [ $? -ne 0 ]
then
echo " Child Process C1 failed !!! "
fi
wait $t2
if [ $? -ne 0 ]
then
echo " Child Process C2 failed !!! "
fi
exit 0
-------------------------------------
Child1
------
#!/bin/bash
echo -e " in child process 1 "
sleep 2
echo -e " in child process 2 "
sleep 2
echo -e " in child process 3 "
sleep 7
exit 0 # success
Child2
------
#!/bin/bash
echo -e " in child process 4"
echo -e " in child process 5"
echo -e " in child process 6"
exit 1 # failed
Thanks,
SSR.
10 More Discussions You Might Find Interesting
1. Solaris
nohup /bin/bassh $HOME/scripts/test.sh > $HOME/log/test.log 2>&1 &
nohup $HOME/scripts/test.sh > $HOME/log/test.log 2>&1 &
Which is the good practice to run a script in background of above two ?
does the first one will have any overhead on the system ?
our system is SunOS 5.10... (2 Replies)
Discussion started by: mmasals
2 Replies
2. Linux
I have script 3 scripts
1 parent
2 children
child1
child2
In the code below the 2 child processes fire almost Instantaneously in the background, Is that possible to know the status of pass/fail of each process "as it happens" ?
In the present scenario although Child2... (5 Replies)
Discussion started by: jville
5 Replies
3. Shell Programming and Scripting
Running centos 2.6, I have a bash script in which I'd like to run a number of background threads in parallel, tee'ing the results of the entire script to one file, while tee'ing the result of each background thread to another.
Here's what I'm doing, where the number of csv files control the... (1 Reply)
Discussion started by: heatlamp
1 Replies
4. Programming
So I made my own unix shell, but i want to make a background process when using the & appended to the end, so far most of the commands seem to work (except cd, but thats another story)
right now here is what I have got.
Im thinking maybe I shouldn't be using switch and maybe switch it to... (27 Replies)
Discussion started by: Mercfh
27 Replies
5. Shell Programming and Scripting
I am trying to use a loop to start tasks 0-3, running 0,1,2 in the background with &.
FOLDSET=( 0 1 2 3 )
for FOLDSET in ${FOLDSET}
do
if ; then
BACKGRD="&"
else
BACKGRD=""
fi
# start task $FOLDSET
task1 -nogui -ni -p $PROJ \
epochs=$EPOS ... (3 Replies)
Discussion started by: LMHmedchem
3 Replies
6. Shell Programming and Scripting
NOTE: I am using BASH and Solaris 10 for this.
Currently in the process of building a script that has a main "watcher" daemon that reads a configuration file and starts background processes based on it's global configuration. It is basically an infinite loop of configuration reading. Some of the... (4 Replies)
Discussion started by: dcarrion87
4 Replies
7. Shell Programming and Scripting
I'm having trouble with part of this bash script in Linux where I respawn a new instance of script and kill the old one to prevent forking (Yes, I know 'exec' will not fork but this needs to be interactive) When the old instance is kill it pops up "Terminated!" in the middle of the new instance... (7 Replies)
Discussion started by: Azrael
7 Replies
8. Shell Programming and Scripting
Hi
Say I am interested in processing a big data set over shell, and each process individually takes a long time, but many such processes can be pipe-lined, is there a way to do this automatically or efficiently in shell?
For example consider pinging a list addresses upto 5 times each. Of... (5 Replies)
Discussion started by: jamie_123
5 Replies
9. Shell Programming and Scripting
I'm completely brand new to bash scripting (migrating from Windows batch file scripting). I'm currently trying to write a bash script that will automatically reset "error-disabled" Cisco switch ports. Please forgive the very crude and inefficient script I have so far (shown below). It is... (10 Replies)
Discussion started by: MKANET
10 Replies
10. Shell Programming and Scripting
Hello! I have got a homework. The bash script runs in the background and checks the user's mailbox and when the user gets a new mail a popup window appears with some text and information about the sender (from who and when).I have no idea how to start, any help would be appreciated! Thank you:) (1 Reply)
Discussion started by: capo2ndfret
1 Replies
Child(3pm) User Contributed Perl Documentation Child(3pm)
NAME
Child - Object oriented simple interface to fork()
DESCRIPTION
Fork is too low level, and difficult to manage. Often people forget to exit at the end, reap their children, and check exit status. The
problem is the low level functions provided to do these things. Throw in pipes for IPC and you just have a pile of things nobody wants to
think about.
Child is an Object Oriented interface to fork. It provides a clean way to start a child process, and manage it afterwords. It provides
methods for running, waiting, killing, checking, and even communicating with a child process.
NOTE: kill() is unpredictable on windows, strawberry perl sends the kill signal to the parent as well as the child.
SYNOPSIS
BASIC
use Child;
my $child = Child->new(sub {
my ( $parent ) = @_;
....
# exit() is called for you at the end.
});
my $proc = $child->start
# Kill the child if it is not done
$proc->complete || $proc->kill(9);
$proc->wait; #blocking
IPC
# Build with IPC
my $child2 = Child->new(sub {
my $self = shift;
$self->say("message1");
$self->say("message2");
my $reply = $self->read(1);
}, pipe => 1 );
my $proc2 = $child2->start;
# Read (blocking)
my $message1 = $proc2->read();
my $message2 = $proc2->read();
$proc2->say("reply");
SHORTCUT
Child can export the child() shortcut function when requested. This function creates and starts the child process in one action.
use Child qw/child/;
my $proc = child {
my $parent = shift;
...
};
You can also request IPC:
use Child qw/child/;
my $child = child {
my $parent = shift;
...
} pipe => 1;
DETAILS
First you define a child, you do this by constructing a Child object. Defining a child does not start a new process, it is just the way to
define what the new process will look like. Once you have defined the child you can start the process by calling $child->start(). One child
object can start as many processes as you like.
When you start a child an Child::Link::Proc object is returned. This object provides multiple useful methods for interacting with your
process. Within the process itself an Child::Link::Parent is created and passed as the only parameter to the function used to define the
child. The parent object is how the child interacts with its parent.
PROCESS MANAGEMENT METHODS
@procs = Child->all_procs()
Get a list of all the processes that have been started. This list is cleared in processes when they are started; that is a child will
not list its siblings.
@pids = Child->all_proc_pids()
Get a list of all the pids of processes that have been started.
Child->wait_all()
Call wait() on all processes.
EXPORTS
$proc = child( sub { ... } )
$proc = child { ... }
$proc = child( sub { ... }, $plugin, @data )
$proc = child { ... } $plugin => @data
Create and start a process in one action.
CONSTRUCTOR
$child = Child->new( sub { ... } )
$child = Child->new( sub { ... }, $plugin, @plugin_data )
Create a new Child object. Does not start the child.
OBJECT METHODS
$proc = $child->start()
Start the child process.
SEE ALSO
Child::Link::Proc
The proc object that is returned by $child->start()
Child::Link::Parent
The parent object that is provided as the argumunt to the function used to define the child.
Child::Link::IPC
The base class for IPC plugin link objects. This provides the IPC methods.
HISTORY
Most of this was part of Parrallel::Runner intended for use in the Fennec project. Fennec is being broken into multiple parts, this is one
such part.
FENNEC PROJECT
This module is part of the Fennec project. See Fennec for more details. Fennec is a project to develop an extendable and powerful testing
framework. Together the tools that make up the Fennec framework provide a potent testing environment.
The tools provided by Fennec are also useful on their own. Sometimes a tool created for Fennec is useful outside the greator framework.
Such tools are turned into their own projects. This is one such project.
Fennec - The core framework
The primary Fennec project that ties them all together.
AUTHORS
Chad Granum exodist7@gmail.com
COPYRIGHT
Copyright (C) 2010 Chad Granum
Child is free software; Standard perl licence.
Child is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
perl v5.10.1 2011-03-07 Child(3pm)