The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-23-2007
smreddy smreddy is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 2
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..
  #2 (permalink)  
Old 12-23-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by smreddy View Post
your suggestions are needed.
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.
  #3 (permalink)  
Old 12-23-2007
smreddy smreddy is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 2
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?
  #4 (permalink)  
Old 12-23-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
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
and the child looks like

Code:
thirdstage()
{
        doalltherest
}

doinitialwork

if status-met
then
     thirdstage &
     exit 0
fi

exit 1
  #5 (permalink)  
Old 12-23-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
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
  #6 (permalink)  
Old 12-23-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by matrixmadhan View Post
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.
You can't use sleep to reliably synchronise between processes, you need to use events and state. In UNIX the the best two events are

(a) a process terminating yielding an exit code

(b) reading of a stream
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0