functor
import
OS
Open
System
export
define
class TextFile from Open.file Open.text
end
class Counter
attr c:1
meth inc c <- @c +1 end
meth set c <- 1 end
meth get(?C) C=@c end
end
proc {Infinite C}
ListPids GetClientsPid File Count in
{Delay 1000*60}
{OS.system "ls /tmp/pidclient* > /tmp/files" _}
File= {New TextFile init(name:"/tmp/files")}
proc {GetClientsPid ?ListPids}
case {File getS($)} of false then ListPids=nil {File close}
elseof S
then
ListPids=S|{GetClientsPid $}
end
end
{GetClientsPid ListPids}
Count={New Counter set}
{ForAll ListPids
proc {$ Fname}
File in
File= {New TextFile init(name:Fname)}
case {File getS($)} of false then{File close}
elseof S
then
if {Count get($)}==C then
{System.show 'client:kill -9'#' '#{StringToAtom S} }
{OS.system "kill -9"#" "#S _}
{OS.system "rm /tmp/pidclient"#S _}
else
skip
end
{Count inc}
end
end
}
{Count set}
local File1 in
try
File1= {New TextFile init(name:'/tmp/pidserver')}
case {File1 getS($)} of false then {File1 close}
elseof S
then
{System.show 'server:kill -9'#' '#{StringToAtom S }}
{OS.system "kill -9"#" "#S _}
end
catch
_
then
skip
end
end
if C< {List.length ListPids $} then
{Infinite C+1}
else
{Infinite 1}
end
end
{Infinite 1}
end