" command does the same thing. But I like to have this as some sort of syscall()...Is any stuff available like this?As a single syscall? Unlikely you'll find such a thing on any.system.....But, that's ">

How to get list of child processes???

Posted by webmaster on January 6th, 2009
  • Is there any system call available to get the list of child process IDs, if we have the process ID as the input. I think through
    "ptree <PID>" command does the same thing. But I like to have this as some sort of syscall()...Is any stuff available like this?


  • My target system is SUN Solaris.

    Yes, exactly the same way I've implemented, by reading the process table and get the ppid(), compare this value with yr available processID.

    Shall we still simplify this process, is there any other way???


  • Check out:

    http://docs.sun.com/db/doc/805-8022-05/6j7ht6u7a?a=view


    Hope that helps...

    Michael


  • As a single syscall? Unlikely you'll find such a thing on any
    system...

    But, that's another thing: you don't mention what system you're
    using... Such a thing is likely to be very system-specific and
    non-portable... So, without knowing your target system, no one
    will really be able to help you...

    But, taking a wild stab in the dark and assuming Linux, you could
    do it fairly easily by simply reading through all "/proc/<pid>/status"
    files, looking at the "PPid" listed, and comparing it against the one
    you're looking for... Something similar probably applies to any
    other "/proc"-based system...


  • Yes, I tried by reading through the process table, in the process info structure for the process..i.e psinfo_t has a variable to get the parent processID. we need to read through /proc/<PID>/psinfo.

    I think this could be the only way to solve the problem,

    See my algorithm below




    pid_t mypid = ::getpid();
    DIR* dir;
    struct dirent *pdirent;

    dir = opendir("/proc/");

    if(!dir)
    return error;

    while((pdirent = readdir(dir)) != NULL)
    {
    if(pdirent->d_name[0] == '.')
    continue;

    string path = string("/proc/") + string(pdirent->d_name) +
    string("/psinfo");
    ifstream file(path.c_str());
    psinfo_t psinfo;

    //chk for error in opening
    file.read((char*)&psinfo, sizeof(psinfo));
    if(psinfo.pr_ppid == mypid)
    cerr<<"LIST THIS ONE"<<endl;
    file.close();

    }


    This is OK I think.







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about How to get list of child processes??? , Please add it free.