"ptree <PID>" command does the same thing. But I like to have this as some sort of syscall()...Is any stuff available like this?
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???
http://docs.sun.com/db/doc/805-8022-05/6j7ht6u7a?a=view
Hope that helps...
Michael
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...
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.# |