This is really really strange.
First of all, I have made a simple shell script, just for testing purposes:
#!/bin/sh
echo "start script"
sleep 2
echo "2"
sleep 2
echo "4"
sleep 2
echo "6"
sleep 2
echo "8"
sleep 2
echo "10"
sleep 2
echo "12"
sleep 2
echo "end script"
When executed from console, no problem, it counts for 14 seconds.
I can also call it from at small program, then I start the script by use of TProcess, here made with at loop that rapidly starts my script ten times, meaning ten running processes:
var
x:integer;
procedure waitforcall;
var
AProcess: TProcess;
begin
writeln('udp start');
AProcess := TProcess.Create(nil);
try
AProcess.InheritHandles := False;
AProcess.Executable:='/bin/sh';
AProcess.Parameters.Add('-c');
Aprocess.Parameters.Add('./startshow');
AProcess.Options:=[];
AProcess.execute;
finally
Aprocess.free;
end;
writeln('udp end');
end;
begin
for x:=1 to 10 do
waitforcall;
end.
So far so good.
Then I want to control this via a multicast, so I created this UDP Multicast listener:
procedure waitforcall;
var
rcvsock:TUDPBlockSocket;
buf:string;
begin
rcvsock:=TUDPBlockSocket.Create;
try
rcvsock.createsocket;
rcvsock.Bind('0.0.0.0','22401');
rcvsock.AddMulticast('239.66.16.10');
buf:=rcvsock.RecvPacket (60000);
if buf='startshow' then
writeln(buf);
finally
rcvsock.free;
end;
end;
begin
while true do
waitforcall;
end.
This also works totally as expected, as fast as I can send "startshow" telegrams over the UDP socket, is writes it on the screen.
However, if I combine the two program like this:
procedure waitforcall;
var
rcvsock:TUDPBlockSocket;
buf:string;
AProcess: TProcess;
begin
rcvsock:=TUDPBlockSocket.Create;
try
rcvsock.createsocket;
rcvsock.Bind('0.0.0.0','22401');
rcvsock.AddMulticast('239.66.16.10');
buf:=rcvsock.RecvPacket (60000);
if buf='startshow' then
begin
writeln('udp start');
AProcess := TProcess.Create(nil);
try
AProcess.InheritHandles := False;
AProcess.Executable:='/bin/sh';
AProcess.Parameters.Add('-c');
Aprocess.Parameters.Add('./startshow');
AProcess.Options:=[];
AProcess.execute;
finally
Aprocess.free;
end;
writeln('udp end');
end;
finally
rcvsock.free;
end;
end;
begin
while true do
waitforcall;
end.
Then the fun begins, because I would expect that for every time I send my UDP telegram, it should execute the startshow command, and start it as a new detached process - but no, it has to wait 14 seconds before it is ready for the next command.
And setting the recsock timeout to a lower value makes no difference (and using poUsePipes just sends the output from script into the blue, the problem remains the same, it takes 14 seconds).
The really, really odd thing is, that it actually outputs:
Udp start
Udp end
Script start
2
....
12
Script end
Which means that the script actually is detached, but still it blocks?
So why is it falling over its own feets?