* * *

Author Topic: Failed to fork a process error in raspberry pi  (Read 149 times)


  • New member
  • *
  • Posts: 8
Failed to fork a process error in raspberry pi
« on: October 11, 2017, 01:01:51 pm »
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];

   if AProcess.ExitStatus=0 then

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.



  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5740
Re: Failed to fork a process error in raspberry pi
« Reply #1 on: October 11, 2017, 02:33:53 pm »
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 case
  • if 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 argument
  • avoid 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.



Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus