in reply to Function to get a child pid

It's not entirely clear to me what you want to do. When you fork the pid of the child is returned to parent. Now you want to call a function that returns the pid of a child process "already running". But a child of... what? Do you mean to call this function in the parent? Then you would have better saved it at fork time instead.

Also you want to "get the child pid of a process running, by just passing only the parent process pid". But a parent can have many childs...

Replies are listed 'Best First'.
Re^2: Function to get a child pid
by Anonymous Monk on Oct 21, 2005 at 13:33 UTC
    fork is not accepting arguments. This will help me when I call this function recursively to find all the child pid.So can you explain me how to pass pid as argument to fork

      Maybe I wasn't clear, and I apologize for that... I wasn't suggesting fork as a function "to get a child pid of a process running, by just passing only the parent process pid". Because I can hardly make sense of such a request.

      Said this, maybe you just want to get a list of all the childs of a given (parent) process. If so, then you may use Proc::ProcessTable to search amongst all processes those that are childs of the given parent. You will be particularly interested in Proc::ProcessTable::Process's ppid() method.

      To put all this together is left as an exercise to the reader.