After a lot of Googling and even a conversation with ChatGPT, I've finally got a rough, but working procedure, it does need a certain amount of checks adding, like empty strings etc, but I think it's a sound basis to work off. One other 'little' thing to throw in the mix, there could already be an existing Qcad process running that I have to avoid closing !!. Here's the code...........
procedure TWSplash.CloseQcadClick(Sender: TObject);
{$IFDEF Linux}
var
CProc: TProcess;
StrList: TStringList;
Str: String;
x: Integer = 0;
{$ENDIF}
begin
{$IFDEF WINDOWS}
Form1.proc.Terminate(0); // process created in the main form
{$ENDIF}
{$IFDEF Linux}
CProc:= TProcess.Create(nil);
StrList:= TStringList.Create;
CProc.Executable:= 'sh';
CProc.Parameters.Add('-c');
CProc.Parameters.Add('pgrep -f qcad-bin');
CProc.Options := CProc.Options + [poWaitOnExit, poUsePipes];
CProc.Execute;
StrList.LoadFromStream(CProc.Output);
x:= StrList.Count;
if x = 2 then Str:= StrList[0];
if x > 2 then Str:= StrList[1];
CProc.Free;
StrList.Free;
fpKill(StrToInt(Str), SIGTERM);
{$ENDIF}
end;
One odd thing is that with one Qcad process running, typing 'pgrep -f qcad-bin' in the terminal gives one line of output, but the TProcess output gives two lines, I can't figure out what the second PID is. With two Qcad processes I know that the one I start in Lazarus is the second line of output. but as I say, it's all a bit rough and ready and needs lots of finessing.
Many many thanks to MarkMLI and TRon for your help and guidance. Also thanks to MarkMLI for giving me the word of the month, possibly year -
fossicking