gulya2005
31st January 2005, 11:04
How to close session from other session? Exists function of the closing not current session.

vahdani
31st January 2005, 13:18
Hi Gulya!

use following:

function main()
{
kill.session.group("tdsls4110m000")
}

function kill.session.group(string i.program(14))
{
long info(PSMAXSIZE)
string progname(14)
long procid, next.procid

procid = -1
next.procid = pstat( procid, progname, info )
while next.procid > 0
procid = next.procid
|get process info
next.procid = pstat( procid, progname, info )
if progname = i.program then
kill.pgrp(procid)
break
endif
endwhile
}


You could also use kill() instead of kill.pgrp() but this may not stop all the sub-processes of a session. For example here I stop the tdsls4110m000 processes group which also terminates tdsls4101m000, tdsls4102s000 and tdsls4503s000 and any other sub-processes which may have been started!

NPRao
31st January 2005, 21:00
You could also use kill() instead of kill.pgrp() but this may not stop all the sub-processes of a session.
Because - A process can have fork subprocess which may be linked into the same or different process group therefore you have to check the parent process id of the sub-process.

You have to make function which would be like - kill.child.process() which takes a process id and then goes through the list of all the processes in the current bshell and finds the matching parent process id and kills them all for a clean close.

vahdani
1st February 2005, 09:44
Thanks NP,

good point! But how do processes fork in Baan? One answer I can think of could be by starting a non Modal Session. Any thougths on this?

NPRao
1st February 2005, 20:28
Refer to the thread -

Launching a Session from within a Session (http://www.baanboard.com/baanboard/showthread.php?t=22322&highlight=process)