Reputation: 1220
Is there relyable way in UNIX to know how many child processes has my certain child process? For example, main process forks child process which exec login
program, can i know whether login
forked or not?
UPD i'm using C
Upvotes: 0
Views: 625
Reputation: 8108
It's crude, but you could just use a popen
version of what this page is doing, and parse the returned values.
Instead of grep
-ing for httpsd
you grep
for your process. Or you could use the --ppid
switch on the ps
command and just get all the child processes of this parent process.
Upvotes: 0
Reputation: 4158
Children are linked via their ppid (parent pid) to the parent, so it's just a matter of following those links, depending on what language you use to implement that. The pstree
command uses this to display the process tree.
Regarding "reliable", you have to handle processes appearing and disappearing all the time, best is to snapshot the running processes as fast as possible, and only then analyze the data.
Upvotes: 1
Reputation: 69260
You have to go through all processes, checking their PPID (Parent Process ID) and compare that to the PID of the process you want the children of.
Upvotes: 0