Re: fork()/exec() and X11 streams usage.
Re: fork()/exec() and X11 streams usage.
- Subject: Re: fork()/exec() and X11 streams usage.
- From: Jeremy Huddleston Sequoia <email@hidden>
- Date: Fri, 12 Oct 2012 10:24:09 -0700
On Oct 12, 2012, at 09:47, Robert Tillyard <email@hidden> wrote:
> Hello, Jeremy,
>
> Thanks for your reply.
>
> Before I call exec() I have to run through open fd's calling fcntl (fd, F_SETFD, 1);
That's not portable. I assume you are setting FD_CLOEXEC.
Why don't you just set the FDs cloexec when you open them? Doing that will save you from having to do that after *every* fork.
This is exactly the inefficiency I was talking about. You're doing a fork, a ton of fcntl (or close() if you go that route), and an exec for every spawned process. You could just have a single posix_spawn if you refactored your code. There are cases where you can't do something with posix_spawn that you may want to between a fork and exec (eg: dup2), but this isn't one of them.
> Would posix_spawn() do this for me?
> Regards, Rob.
>
> On 12 Oct 2012, at 08:11, Jeremy Huddleston Sequoia wrote:
>
>> No. posix_spawn is more efficient. At base, it's a single syscall instead of at-least 2. Beyond that, it allows the kernel to skip some possibly unnecessary action in setting up the new process... For example CLOEXEC fds would be created for the new process only to be destroyed on the subsequent exec...
>>
>> --Jeremy
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
X11-users mailing list (email@hidden)
This email sent to email@hidden