Hi,
A process initiated by a command with & at the end in shell script
should wait for completion of the process which started it. How this
could be done? ("wait()" waits only for child processes). How do I
find the pid to wait for?
Thanks.
Thanks.
> Hi,
> A process initiated by a command with & at the end in shell script
> should wait for completion of the process which started it. How this
> could be done? ("wait()" waits only for child processes). How do I
> find the pid to wait for?
> Thanks.
If you are stating that child processes wait for their parents,
i'm afraid you've got it backwards.
In shell scripts "wait" is typically used to stall processing (of
the script) until the backgrounded command returns.
If on the other hand, your problem is to resume a suspended child
process when its parent (shell script) terminates, something can be
approximated with kill(1) and trap, as per:
#!/bin/sh
trap 'kill -CONT $cmdPID' 0
keypress=' '
cmdPID=
# something that takes a while to run
#
alias cmd="find / -name '*.a' -print"
cmd&
# $! refers to the PID of most recently backgrounded process.
# The construct: wait $! in shell scripts is common.
#
cmdPID=$!
# Signals are _not_ "job control",
# although they can be used to control jobs. In other words,
# doing fg or bg in above trap won't work.
#
kill -STOP $cmdPID
while [ "$keypress" != q ]
do
read -p "enter q to quit " keypress
done
# trap catches here
#
exit
cheers,
tom
-- Why not just drop everything and go fishin'?
remove NO_SPAM. from address to reply
1. how do i wait for child processes, and *their* children to finish
hi,
the function waitpid allows me to wait on a child process. however, if
that child process fork()s children of its own, and then returns,
waitpid will return also. i want a way of waiting for the
'grandchildren' also.
thanx for your help,
ittay
3. wait for the child process from other process
4. Cannot fix my return address, sendmail help wanted....
5. Child Process Waiting for Parent Process
6. PCMCIA network card troubles w/4.1.1
7. Supervising non-child processes w/wo procfs
8. XFree86 "Startup Group" equivalent?
9. Can I ptrace(2) a non-child process ?
10. smail failed to reap child process: No child processes
11. how to kill a child process that runs other children processes
12. Getting a child and child's child process-id