![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can a child process return a specific value to a parent process ? | Ametis1970 | High Level Programming | 8 | 04-09-2008 11:22 PM |
| Process State | ianlow | UNIX for Dummies Questions & Answers | 1 | 09-06-2006 10:11 AM |
| gdb to child process | shriashishpatil | UNIX for Advanced & Expert Users | 4 | 12-12-2005 07:57 AM |
| KDM child process | larryase | UNIX for Dummies Questions & Answers | 6 | 01-24-2005 05:41 PM |
| Child Process PID | skannan | High Level Programming | 2 | 06-10-2002 07:54 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
child process state
Hi all,
I have one requirement,I have two shell programs one is parent and the other one is child . from parent script i need to execute/trigger/call child script as background job. my requirement is after calling child script i want the child process information i.e PID of child weather it is still running or not? I am written the following code in parent shell which returns 2 everytime i.e the output is "child not running". /tmp/child.sh & ChildPIDRunningStatus=`ps -ef | grep $! | grep -v grep | wc -l` if [ $ChildPIDRunningStatus -gt 2 ]; then echo "child is running" else echo "child is not running" fi your suggestions are needed. Last edited by smreddy; 12-23-2007 at 04:47 AM.. |
|
||||
|
If you are doing the test immediately after starting it and doing the test one only then you might as well assume that it *always* starts and is still running due to the independent nature of processes.
Are you going to repeatedly check the status of the child process, if so grab the $! value into a variable and check against that. |
|
||||
|
child process state
Hi,
Thanx for reply, I am not testing the child status repeatedly.testing only once after calling that as you said it should run.the child script contain some logic that runs for a while. depending upon that status i need to do further processing. to go ahead the child status should return it is running. if not i am unable to go ahead. i tried with that what you suggested to assign that into a variable. in that case also same result i am getting. do u have any other ideas? |
|
||||
|
Do you mean
1. start child 2. test if child has reached a certain status 3. if so do another task The problem you have is what time interval/synchronisation are you doing between 1 and 2? Imagine the child starts but takes a while to reach the certain status? Why not have the child do 1. do initial work to determine the magic status 2. if the status is met, 2.1 spawn another child to continue the child tasks 2.2 return the status as the exit code Then all you need to do is Code:
if child
then
dothisothertask
fi
Code:
thirdstage()
{
doalltherest
}
doinitialwork
if status-met
then
thirdstage &
exit 0
fi
exit 1
|
|
||||
|
Is the status logged in a file?
Then it would be much more easier to identify the step from where other process can continue processing. But again the granularity between sleeping and checking for any log messages is purely experimental and you have to give a random number for that. parent process - starts the child process child process logs the info in a file controller process checks whether necessary message has been logged into file or not if not then continue sleeping if yes continue with the next steps |
|
||||
|
Quote:
(a) a process terminating yielding an exit code (b) reading of a stream |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|