How to wait for a grand child to finish?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to wait for a grand child to finish?
# 8  
Old 12-18-2014
Scripting can catch $? and store it, but I am not sure any shell lets you capture the terminating signal. You can write a C wrapper for that, where the parent does the fork(), execvp() and logs the wait() response.
https://www.unix.com/man-page/linux/2/wait/
PERL probably can do this too, and python. The grandparent cannot.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

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

How to wait for tar to finish before sending the archive through ftp?

Hey all, I want to automate tarring a directory then using ftp to transfer the files over. I was able to put the commands together but what I'm noticing is that only the very first file is being tarred and then transferred. tar cvpf new.backup sourceAbove is the command I'm using which works... (4 Replies)
Discussion started by: Keepcase
4 Replies

4. Shell Programming and Scripting

How to WAIT for jobs in each group to finish?

I have the shell script to call a Perl routine and pass the Informatica WorkFlow name to it. Jobs in each group executes in background do not seem to wait at all. How do I make it to WAIT for the prior group to complete before execute the next group of jobs? Sample of the jobs flow: { ... (6 Replies)
Discussion started by: lv99
6 Replies

5. Programming

Parent,child wait,signal

Hello. I want to make a child do some stuff,wait,then the parent does some stuff and then child does some stuff and waits again.I have made the following but it does not work.Can anybody help me? pid1 = fork(); if (pid1 == -1) { perror("Can't create child\n"); ... (18 Replies)
Discussion started by: Cuervo
18 Replies

6. 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

7. 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

8. Shell Programming and Scripting

How to wait for the subprocess to finish in tcl

Hi All Here i have a piece of code, set filename "./GopiRun.sh" #I need to wait here until the GopiRun.sh is completed how do i achive this exit. (1 Reply)
Discussion started by: nathgopi214
1 Replies

9. Programming

Howto spawn multiple child processes and wait?

As far as I can tell, the bash wait command waits for a logical "AND" of all the child processes. Assuming I am coding in C: (1) What is the function I would use to create multiple bash child process running perl? (2) What is the function I would use to reinvent the bash wait command so I... (4 Replies)
Discussion started by: siegfried
4 Replies

10. UNIX for Advanced & Expert Users

How can I wait for PID to finish in another shell

Have a need to schedule programs that can run after other programs are completed. Here's the catch: 1) The list of programs will not always be the same (kind of a plug-n-play deal) 2) The invoking shell may not be the same as the shell of the program being waited on In other words, I need... (2 Replies)
Discussion started by: superdelic
2 Replies
Login or Register to Ask a Question
wait(3C)						   Standard C Library Functions 						  wait(3C)

NAME
wait - wait for child process to stop or terminate SYNOPSIS
#include <sys/types.h> #include <sys/wait.h> pid_t wait(int *stat_loc); DESCRIPTION
The wait() function will suspend execution of the calling thread until status information for one of its terminated child processes is available, or until delivery of a signal whose action is either to execute a signal-catching function or to terminate the process. If more than one thread is suspended in wait(), waitpid(3C), or waitid(2) awaiting termination of the same process, exactly one thread will return the process status at the time of the target process termination. If status information is available prior to the call to wait(), return will be immediate. If wait() returns because the status of a child process is available, it returns the process ID of the child process. If the calling process specified a non-zero value for stat_loc, the status of the child process is stored in the location pointed to by stat_loc. That status can be evaluated with the macros described on the wait.h(3HEAD) manual page. In the following, status is the object pointed to by stat_loc: o If the child process terminated due to an _exit() call, the low order 8 bits of status will be 0 and the high order 8 bits will contain the low order 7 bits of the argument that the child process passed to _exit(); see exit(2). o If the child process terminated due to a signal, the high order 8 bits of status will be 0 and the low order 7bits will contain the number of the signal that caused the termination. In addition, if WCOREFLG is set, a "core image" will have been produced; see signal.h(3HEAD) and wait.h(3HEAD). One instance of a SIGCHLD signal is queued for each child process whose status has changed. If wait() returns because the status of a child process is available, any pending SIGCHLD signal associated with the process ID of that child process is discarded. Any other pending SIGCHLD signals remain pending. If the calling process has SA_NOCLDWAIT set or has SIGCHLD set to SIG_IGN, and the process has no unwaited children that were transformed into zombie processes, it will block until all of its children terminate, and wait() will fail and set errno to ECHILD. If a parent process terminates without waiting for its child processes to terminate, the parent process ID of each child process is set to 1, with the initialization process inheriting the child processes; see Intro(2). RETURN VALUES
When wait() returns due to a terminated child process, the process ID of the child is returned to the calling process. Otherwise, -1 is returned and errno is set to indicate the error. ERRORS
The wait() function will fail if: ECHILD The calling process has no existing unwaited-for child processes. EINTR The function was interrupted by a signal. USAGE
Since wait() blocks on a stopped child, a calling process wanting to see the return results of such a call should use waitpid(3C) or waitid(2) instead of wait(). The wait() function is implemented as a call to waitpid(-1, stat_loc, 0). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Async-Signal-Safe | +-----------------------------+-----------------------------+ SEE ALSO
Intro(2), exec(2), exit(2), fork(2), pause(2), waitid(2), ptrace(3C), signal(3C), signal.h(3HEAD), waitpid(3C), wait.h(3HEAD), attributes(5) SunOS 5.11 9 Jun 2004 wait(3C)