Problem with file descriptors when doing fork on linux

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with file descriptors when doing fork on linux

ko paka
Hello,

I would like to ask advice. My colleague run into a problem, when he had used TProcess to spawn other process. Because of fork nature, file descriptors was copied into newly created process.
He found that for such cases CLOEXEC flag exists to be used when open file. I found flag declared in various units inside fpc, but nowhere to be used. So when I need to use it I need to make some own routine?
Or more generally do exists in fpc some other way how to deal with this problem - to create new process but without copied file descriptors?

tomas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Problem with file descriptors when doing fork on linux

Michael Van Canneyt


On Fri, 2 Feb 2018, Ko Paka wrote:

> Hello,
>
> I would like to ask advice. My colleague run into a problem, when he had
> used TProcess to spawn other process. Because of fork nature, file
> descriptors was copied into newly created process.
> He found that for such cases CLOEXEC flag exists to be used when open file.
> I found flag declared in various units inside fpc, but nowhere to be used.
> So when I need to use it I need to make some own routine?

I have added it to the linux unit:

Const
   O_CLOEXEC = $80000;

If you want to use it today, you'll need to add it to your own units
manually.

> Or more generally do exists in fpc some other way how to deal with this
> problem - to create new process but without copied file descriptors?

No, currently not.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Problem with file descriptors when doing fork on linux

Luca Olivetti-2
El 02/02/18 a les 11:33, Michael Van Canneyt ha escrit:

>
>> Or more generally do exists in fpc some other way how to deal with this
>> problem - to create new process but without copied file descriptors?
>
> No, currently not.



Why doesn't the unix implementation take into account the InheritHandles
property?

Bye
--
Luca
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal