Failed to Fork error lazarus / 62-General ---------------------------------------------------------------------- BLL · 2015-10-19 18:43 Hi, I am getting this strange error message of "Failed to Fork Process" (I presume Linux has problems eating dinner!!) It is coming about when I run the following procedure, which is called once a second to launch a command line program called te923con, which reads data over USB from my weather station. I am crfeating and freeing TProcess and TStream and creating/destroying the variables on end procedure, except for the StringList, which is globally available and is created in FormCreate and freed on program exit, so I don't see where the resources/memory are being gobbled up. I am using a Raspberry Pi, model 2 with Lazarus 1.5 and fpc 3.1.1: procedure TMainForm.doWeather; var temp:String; WxProcess    : TProcess; OutputStream : TStream; BytesRead    : longint; Buffer       : array[1..BUF_SIZE] of byte; begin  WxProcess := TProcess.Create(nil);  WxProcess.Executable := progPath + 'te923con';  //Process option poUsePipes has to be used so the output can be captured.  //Process option poWaitOnExit can not be used because that would block  //this program, preventing it from reading the output data of the process.  WxProcess.Options := [poUsePipes];  WxProcess.Execute;  OutputStream := TMemoryStream.Create;  //All generated output from AProcess is read in a loop  //until no more data is available  repeat   //Get the new data from the process to a maximum of the   //buffer size that was allocated.   //Note that all read(...) calls will block except for the last one,   //which returns 0 (zero).   BytesRead := WxProcess.Output.Read(Buffer, BUF_SIZE);   //Add the bytes that were read to the stream for later usage   OutputStream.Write(Buffer, BytesRead)   until BytesRead = 0;  // Stop if no more data is available  OutputStream.Position := 0; // Required to make sure all data  //is copied from the start  WxList.Clear;  WxList.LoadFromStream(OutputStream);  temp := WxList.Strings[0];  WxList.DelimitedText := temp;  OutputStream.Free;  WxProcess.Free; end; Buffer is declared globally as const BUF_SIZE = 256; The program runs for a few hours but then I get the Fork message. Any help much appreciated. Thanks ---------------------------------------------------------------------- Jonas Maebe · 2015-11-10 13:40 If you don't use poWaitOnExit, you have to call WxProcess.WaitOnExit at the end to properly reap the child process. If you don't do that, it will remain as a zombie and you'll indeed run out of process handles for your user id. ---------------------------------------------------------------------- BLL · 2015-11-10 19:39 Hi, Thanks for that. I will try it. I did switch to RunCommand, which is much simpler but I still get the problem. Brian