Se puede acceder de forma recursiva a los hijos de un proceso?
Lo pregutno por si hay alguna forma ya pensada. A mí se me ocurre un array dinamico con las ids de los hijos, o acceder a todos los procesos e ir comprobando si la id de su padre es la misma id que la de mi proceso. ¿alguna otra sugerencia?
There is a local variable Son (http://wiki.bennugd.org/index.php?title=Son) and you can use it with Bigbro (http://wiki.bennugd.org/index.php?title=Bigbro) to obtain all the children of a process:
import "mod_proc"
import "mod_say"
Process Main()
Private
int sonID;
Begin
Proc();
Proc();
Proc();
sonID = son;
while(sonID)
say("Son: " + sonID);
sonID = sonID.bigbro;
end
signal(ALL_PROCESS,S_KILL);
End
Process Proc()
Begin
Loop
frame;
End
End
;D sandman you are crack
karma up
Thanks. :)
If you want to do a full recursion (preorder), you can do this:
import "mod_proc"
import "mod_say"
Process Main()
Private
int sonID;
Begin
Proc();
Proc();
Proc();
say("Preorder Search:");
Traverse_Offspring_PreOrder(0,id);
signal(ALL_PROCESS,S_KILL);
End
Process Proc()
Begin
Proc2();
Proc2();
Loop
frame;
End
End
Process Proc2()
Begin
Loop
frame;
End
End
Function int Traverse_Offspring_PreOrder(int level, int procID)
Begin
if(!procID)
return 0;
end
say( level + " > " + procID);
procID = procID.son;
while(procID)
if(procID.reserved.process_type != type Traverse_Offspring_PreOrder)
Traverse_Offspring_PreOrder(level+1, procID);
end
procID = procID.bigbro;
end
End
Note that if(procID.reserved.process_type != type Traverse_Offspring_PreOrder) is important, because else the Traverse_Offspring_PreOrder process is counted too. This is important for all levels.
[EDIT]
I edited the code, because it could go wrong if Traverse_Offspring_PreOrder() was called from a descendant.
Tambien existe smallbro
Modified the code a bit, because there were situations where it could have gone wrong.
Thanks sandman, karma up!