Failed to fork a process error in raspberry pi lazarus / 1-Linux ---------------------------------------------------------------------- gayathri · 2017-10-11 11:01 Hello All, I am starting a process using TProcess in raspberry pi. This is done in a loop. The loop runs successfully for half a day and then stops with an error 'Failed to fork a process'. This is the code that I am using:   command:='sudo /sbin/ip link set __INTERFACE__ up type can bitrate __BAUDRATE__';   command := StringReplace(command,'__INTERFACE__',interfacename,[]);   command := StringReplace(command,'__BAUDRATE__',baudrate,[]);    AProcess := TProcess.Create(nil);    AProcess.Options := AProcess.Options + [poWaitOnExit,poUsePipes];    AProcess.CommandLine:=command;    Aprocess.Execute;    if AProcess.ExitStatus=0 then       Result:=0    else       Result:=-1;    AProcess.Free;  I have tried adding AProcess.WaitForExit after Aprocess.Execute line and also tried manually killing the Aprocess using the function fpKill(AProcess.ProcessID,SIGKILL) or also used this function fpKill(AProcess.ProcessID,SIGINT). I have also tried removing poUsePipes option. None of them is working out and the same error occurs again and again. Please help me in finding a solution for this problem. Thanks! Regards, Gayathri ---------------------------------------------------------------------- marcov · 2017-10-11 12:33 I've no experience with TProcess and sudo commands, but : My guess is that first working but then later stopping means that you leak processes somewhere and hit the process limit. This is probably because sudo is special. Some tips: .commandline is deprecated, use the new style, and specially in this caseif you have programs that run a commandline for you, like sudo or sh -c,  it might be that the whole commandline should be in one argumentavoid pousepipes since you don't need it. Try first executing a shell (so sh,' -c','sudo ...') If the problem persist, try to find out which process leaks (sudo or the child process, or another one spawned by "ip"), and/or use strace.