perfbook.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Elad Lahav <e2lahav@gmail.com>
To: perfbook@vger.kernel.org
Subject: 7.5.2.7: Library Functions Used Between fork() and exec()
Date: Fri, 14 Oct 2022 08:14:42 -0400	[thread overview]
Message-ID: <CAJbg=FU6Sa=vc6DRGsewXMP6N1Hz2HHUsKkgNTUzPx9Bh0VuKQ@mail.gmail.com> (raw)

Ah, multi-threaded fork, my arch-nemesis.

A few points, though I'm not sure any of these are worth mentioning in the book:

1. It should perhaps be made clear that the child's copy of the lock
is, in fact, a separate lock. The statement that the lock is held by a
parent thread is somewhat inaccurate. That is, unless the lock is in
explicitly-shared memory (i.e., the result of mmap(MAP_SHARED)), in
which case the lock is indeed the same and is (presumably) meant to be
shared between the parent and child.

2. POSIX explicitly says that you can't execute any
non-async-signal-safe functions between fork() and exec(), which
pretty much eliminates any function that acquires a lock.

3. posix_spawn() is a safer alternative to the fork()/exec() pair
(though not to fork() by itself), at least with sensible
implementations that don't devolve to fork() and exec().

--Elad

             reply	other threads:[~2022-10-14 12:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-14 12:14 Elad Lahav [this message]
2022-10-19 23:32 ` 7.5.2.7: Library Functions Used Between fork() and exec() Paul E. McKenney
2022-10-19 23:51   ` Elad Lahav

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJbg=FU6Sa=vc6DRGsewXMP6N1Hz2HHUsKkgNTUzPx9Bh0VuKQ@mail.gmail.com' \
    --to=e2lahav@gmail.com \
    --cc=perfbook@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).