[fpc-pascal] Incorrect Process startup

Ewald ewald at yellowcouch.org
Mon Nov 7 22:10:05 CET 2016

On 06/11/16 23:50, Steve Gatenby wrote:
> run wmctrl (or other) from the TProcess / RunCommand code
> the TProcess instance returns the PID for the new process
> read the relevant file under /proc/PID/status - it will intermittently
> show the new process is actually a copy of the caller app.
> (meaning: the orig app is called Test1, I try to run wmctrl, I end up
> with 2 copies of Test1 running)

Actually, this is quite exactly what I would expect here. Spawning a new
process on unix is actually a two step thingie:
	- First fork(), which duplicates the current process
	- The child then exec()'s, replacing its current process image
          with a new one (which would be the target executable in your

It is important to note that a lot of the parent process is preserved by
the child process. On such example are file descriptors, which are not
closed automatically for you. It is actually via this mechanism that
pipes to and from child processes can be established with relative ease.

More on this subject can be found at

> I have found through experimenting:
> a pause of 100ms after running the process will fix 80% of cases.

Probably because the child has exec'ed by this time, if I had to guess.


More information about the fpc-pascal mailing list