Re: [fpc-pascal] TProcess Running is unreliable on Linux

2021-12-05 Thread Anthony Walter via fpc-pascal
Okay, this is a bit longish but related to my problem. I wrote this remote
terminal program which is explained somewhat in the video below. This is
where I am having the issue with Running sometimes not correctly reporting
the proper value.

https://www.twitch.tv/videos/1224798488
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TProcess Running is unreliable on Linux

2021-12-05 Thread Michael Van Canneyt via fpc-pascal



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.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal