Is a successful call to write(2) atomic?

Paul Procacci pprocacci at gmail.com
Wed Jun 16 02:40:35 UTC 2021


>> On reread, I see that Paul suggested that originally, many pipes, and
>> that's what I was thinking. Paul's writing may not have been perfectly
>> clear.

This is what I was advocating for.  Sorry if that wasn't clear.
It might make sense to provide a visual representation using C pseudo code:

while(children_needed){
  int pipes[2];
  pipe(pipes);
  switch(vfork()){
    case -1: _exit(123);
    case 0:
       /** Remove/Move unnecessary fds - fcntl(2) for example - make one
end of the pipe the child's stdout maybe? */
       exec();
       _exit(123);
  }
  /** Remove/Move unnecessary fds - fcntl(2) for example */
  /** Store other end of pipe fd to poll later - can use an fdset for use
with select(2) or kqueue(2) */
  --children_needed;
}

The above, again just pseudo code, describes what I meant, which is
essentially  ... a Parent orchestrating the children .... reading their
ends of the pipes for their childrens input ... and then later on (not
shown in the pseudo code), doing something with that data.
The above is probably a bit winded, but I felt the need to describe what I
specifically meant, and there's no better way to do that with actual code,
even if it's pseudo code.

By the looks of it, I think we both meant the same exact thing.  ;)

~Paul

* Full Warning - The above code needs a lot of work like checking return
values of syscalls and acting accordingly.  Do not use it as is.  It was
only thrown together to provide a quick visual representation.



On Tue, Jun 15, 2021 at 8:19 PM Kurt Hackenberg <kh at panix.com> wrote:

> On 2021/06/15 19:55, Ronald F. Guilmette wrote:
>
> >> But it works by just changing the messaging mechanism a little: Have
> >> many pipes, one for each sender, all sending to the single write
> >> process, which uses the system call select() to wait for activity on any
> >> of them.
> >
> > You're correct!  That sounds like a nice solution.
>
> On reread, I see that Paul suggested that originally, many pipes, and
> that's what I was thinking. Paul's writing may not have been perfectly
> clear.
>
> Let us know whether it works.
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "
> freebsd-questions-unsubscribe at freebsd.org"
>


-- 
__________________

:(){ :|:& };:


More information about the freebsd-questions mailing list