[fpc-devel] inheriting handles using TProcess in unix

Henry Vermaak henry.vermaak at gmail.com
Thu Jan 27 15:20:56 CET 2011

On 26 January 2011 22:19, Seth Grover <sethdgrover at gmail.com> wrote:
> http://www.freepascal.org/docs-html/fcl/process/tprocess.inherithandles.html
> says "On Unix, setting this variable has no effect." Why is this?
> The reason I ask is that often when using TProcess I run into the
> problem where if I execute some script or program which perhaps forks
> and outlives my original fpc process that this new forked process
> inherits all of the open descriptors belonging to my original process,
> which is usually not what I want.

You can prevent file descriptors from surviving an exec by setting the
FD_CLOEXEC flag for that file descriptor with fcntl().  This is
obviously not thread safe, so there is an O_CLOEXEC flag for open().

See here:



More information about the fpc-devel mailing list