Hi, bharath.gct,
The actual problem is, as you may have already guessed, not
to discover the pids, whether they are children or not (by the way,
with a single exception, every process is a child to another one.)
The actual problem is that YOU CAN'T wait (thru the "wait" command
in shell, or the wait(2) system call in a binary program) for a process
which was not launched by you (your shell or your program).
Wait can only be used with children processes that you directly
spawned (actually, fork(2)'d) - like when your shell launches a
command to the background, via "&".
So, if the process you want to wait for is not of your own, direct,
"breed", sorry, you'll have to figure out some other way to do it.
"Wait" wasn't designed for that, only for actual children, and not for
siblings, cousins, nephews, grandsons, mothers-in-law (or total
strangers) kind of processes.
One way could be, once you discover the pid, keep checking, say, every
1 or 5 seconds, ps output until the process disappears... not very efficient,
but effective.
Hope this helps.
Mario.