Visit Our UNIX and Linux User Community


How to make the parent process to wait for the child process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to make the parent process to wait for the child process
# 1  
Old 09-21-2009
How to make the parent process to wait for the child process

Hi All,

I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program.

I want 1st script to wait until the 'C' program completes.

I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second script(child script) to complete

Can any one help me, how to get the process id for the 'C' program in unix shell script or is there any other way to make the parent script to wait for the child process.

Thanks in advance.
sennidurai
# 2  
Old 09-21-2009
Just 'wait'. Or don't put the C program in the background.
# 3  
Old 09-21-2009
i have use wait, wait $PID and then wait $!. but the process will not wait for the child process.
# 4  
Old 09-21-2009
Where did you use wait? Only the parent process can wait for any child, so if you start the program in the second script, you'll have to wait for it in the second script, not the first.

Another way would be to save the PID in a temporary file, which is then read in the first script. Then the first script checks the process list until it's no longer listed, eg:
Code:
while [ "$( ps -p ${PID} >/dev/null 2>&1; echo $?)" == "0" ]
do
    sleep 1
done

# 5  
Old 09-22-2009
yes it will help, our script is running in production and we dont have the permission to edit the second script (ie. C program). we have to achieve this thru first script only.

Is there any other way to do this.

Thanks,
Sennidurai.
# 6  
Old 09-22-2009
Just to clear this up:
  • You're calling a shell script
  • This is calling a second shell script
  • This second script calls a program written in C, and puts it in the background
  • You're not allowed to change the second script
  • You want to wait for the program to finish in the first script

Right so far?
# 7  
Old 09-30-2009
yes pludi you are right

Previous Thread | Next Thread
Test Your Knowledge in Computers #285
Difficulty: Easy
AIX was the first operating system to have a proc file system.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Wait till any one child process finishes

Hi I am facing a problem in my ksh. My main script is calling 3 different child process in the background. I am using wait to finish all and then submit another 3 child processes. Now what i want is , whenever any one child process finishes ,i want to submit next one.so that parallel 3... (2 Replies)
Discussion started by: Sangu
2 Replies

2. Shell Programming and Scripting

How make parent to wait from child process?

Hi all, I am starting mgen5 for sometime depends on input from a file, in a child process. now I want to make parent to wait in this child process till mgen5 finishes, or timeout happens. could anyone please tell me how to make parent to wait in child process in shell script? thanks... (2 Replies)
Discussion started by: girijajoshi
2 Replies

3. Shell Programming and Scripting

parent process needs to wait

I have two scripts lets say A.expect and B.sh needs to be executed. I am executing B.sh from A.expect where B.sh has sleep command. My problem is that when B.sh encounters the sleep command my A.expect starts executing and exits. but my A.expect should execute only after completing B.sh. Is... (3 Replies)
Discussion started by: priya@2012
3 Replies

4. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

5. Emergency UNIX and Linux Support

signal between parent process and child process

Hello, everyone. Here's a program: pid_t pid = fork(); if (0 == pid) // child process { execvp ...; } I send a signal (such as SIGINT) to the parent process, the child process receive the signal as well as the parent process. However I don't want to child process to receive the... (7 Replies)
Discussion started by: jackliang
7 Replies

6. UNIX for Dummies Questions & Answers

Command to find parent and child process?

Hi, I have a script that calls other scripts/commands which may or may not spawn other process. From my understanding, when I do a ps -ef, the highest numbered process ID is supposed to be the parent ID of all the other related child processes, is this correct? In most or all... (3 Replies)
Discussion started by: newbie_01
3 Replies

7. Shell Programming and Scripting

Make cron wait for the child process

I am trying to find a list of files and writing it to a text file. Based on the machine performance the file writing will be slow at certain time. The code to find file and redirecting the output to text file is on a shell script /usr/bin/find $SEARCH_DIR -daystart \( \( -name 'KI*' -a... (4 Replies)
Discussion started by: nuthalapati
4 Replies

8. Shell Programming and Scripting

[KSH/Bash] Starting a parent process from a child process?

Hey all, I need to launch a script from within 2 other scripts that can run independently of the two parent scripts... Im having a hard time doing this, if anyone knows how please let me know. More detail. ScriptA (bash), ScriptB (ksh), ScriptC (bash) ScriptA, launches ScriptB ScirptB,... (7 Replies)
Discussion started by: trey85stang
7 Replies

9. UNIX for Advanced & Expert Users

how to make a parent wait on a child shells running in background?

Hi I have a shell script A which calls another 10 shell scripts which run in background. How do i make the parent script wait for the child scripts complete, or in other words, i must be able to do a grep of parent script to find out if the child scripts are still running. My Code: ... (1 Reply)
Discussion started by: albertashish
1 Replies

10. Programming

parent and child process question?

Hi everybody, I'm trying to understand how a parent and child processes interact. This function( below) basically measures the fork time from the perspective of the parent only. what i would like to know is how to measure the time from the perspective of parent and child (ie: inserting... (0 Replies)
Discussion started by: tosa
0 Replies

Featured Tech Videos