[fpc-pascal] TProcess Running is unreliable on Linux
Michael Van Canneyt
michael at freepascal.org
Sun Dec 5 09:43:56 CET 2021
On Sun, 5 Dec 2021, Anthony Walter via fpc-pascal wrote:
> On Linux using 3.3.1 build of FPC I've found that in many situations the
> Running property of TProcess is unreliable. Is this a problem with
> which anyone is familiar? I've searched around and haven't found any
> discussions related to this problem.
I've never known it to report falsely.
Reading 'Running' finally does a WaitPID call and this is a kernel call:
Function TProcess.PeekExitStatus : Boolean;
var
res: cint;
begin
repeat
res:=fpWaitPid(Handle,pcint(@FExitCode),WNOHANG);
until (res<>-1) or (fpgeterrno<>ESysEINTR);
result:=res=Handle;
if peekexitstatus returns true (i.e. the process has exited) then running is
set to false.
Try running your program under strace
strace -f --trace=%process yourprogram
(so it only shows process management calls) and see what waitpid returns.
Michael.
More information about the fpc-pascal
mailing list