Lista de hijos.

Started by Danielo515, June 17, 2009, 12:27:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Danielo515

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?

Sandman

There is a local variable Son and you can use it with 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
-- Sandman

syous

 ;D sandman you are crack

karma up
Un Saludo
EL dia que la humanidad aprenda a mirar y sentir con los ojos del alma, recuperara su humanidad
http://sodonline.net/
http://darknessage.ayudaprogramacion.net/
http://www.ayudaprogramacion.net/

Proyecto: MMORPG
Completado: 2%
Estado: En Desarrollo...

Sandman

#3
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.
-- Sandman

SplinterGU

Tambien existe smallbro
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

Sandman

Modified the code a bit, because there were situations where it could have gone wrong.
-- Sandman

Danielo515

Thanks sandman, karma up!