#!/bin/ksh
#
#ident	"@(#)child	1.6	04/12/15 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

[ $# -ne 1 ] && ( echo "Child: Syntax: child PID"; exit 1; )
(echo $1; /bin/ps -el) |
nawk '
        NR == 1 { parentid = $1 }
        NR >  2 { pid[++j] = $4; ppid[j] = $5 }
        END {
                lincnt = j
                findchild(parentid)
                for (j = i; j > 0; --j)
                        printf("%s ", kl[j])
                printf("\n")
        }

        function findchild(procid,   j)
        {
                for (j = 1; j <= lincnt; ++j)
                {
                        if(procid == ppid[j])
                        {
                                kl[++i] = pid[j]
                                findchild(pid[j])
                        }
                }
        }'

exit 0
