Provided by: manpages-ru-dev_4.27.0-1_all bug

НАИМЕНОВАНИЕ

       pthread_atfork - регистрирует обработчики ветвления

БИБЛИОТЕКА

       Библиотека потоков POSIX (libpthread, -lpthread)

ОБЗОР

       #include <pthread.h>

       int pthread_atfork(void (*prepare)(void), void (*parent)(void),
                          void (*child)(void));

ОПИСАНИЕ

       The pthread_atfork()  function registers fork handlers that are to be executed when fork(2)  is called by
       any thread in a process.  The handlers are executed in the context of the thread that calls fork(2).

       Можно регистрировать три типа обработчиков:

       •  prepare specifies a handler that is executed in the parent process before fork(2)  processing starts.

       •  Типом  parent задаётся обработчик, который выполняется в родительском процессе после завершения работы
          fork(2).

       •  Типом child задаётся обработчик, который выполняется в потомке после завершения работы fork(2).

       Любой из трёх аргументов может быть равен NULL, если обработчик  не  требуется  на  соответствующем  шаге
       работы fork(2).

ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ

       On success, pthread_atfork()  returns zero.  On error, it returns an error number.  pthread_atfork()  may
       be  called  multiple times by a process to register additional handlers.  The handlers for each phase are
       called in a specified order: the prepare handlers are called in reverse order of registration; the parent
       and child handlers are called in the order of registration.

ОШИБКИ

       ENOMEM Could not allocate memory to record the fork handler list entry.

СТАНДАРТЫ

       POSIX.1-2008.

ИСТОРИЯ

       POSIX.1-2001.

ПРИМЕЧАНИЯ

       When fork(2)  is called in a multithreaded process, only the calling thread is duplicated  in  the  child
       process.   The original intention of pthread_atfork()  was to allow the child process to be returned to a
       consistent state.  For example, at the time of the call to fork(2), other threads may have locked mutexes
       that are visible in the user-space memory duplicated in the child.  Such mutexes would never be unlocked,
       since the threads that placed the locks are not duplicated in the child.  The intent of  pthread_atfork()
       was  to  provide  a mechanism whereby the application (or a library)  could ensure that mutexes and other
       process and thread state would be restored to a consistent state.  In practice, this  task  is  generally
       too difficult to be practicable.

       В  многонитевом  процессе fork(2) возвращает управление в потомок; потомок должен вызывать только функции
       async-signal-safe (смотрите signal-safety(7)) до момента, пока не вызовет execve(2) для выполнения  новой
       программы.

       В POSIX.1 указано, что pthread_atfork() не должен завершаться ошибкой EINTR.

СМОТРИТЕ ТАКЖЕ

       fork(2), atexit(3), pthreads(7)

ПЕРЕВОД

       Русский     перевод     этой    страницы    руководства    разработал(и)    Alexey,    Azamat    Hackimov
       <azamat.hackimov@gmail.com>,      kogamatranslator49      <r.podarov@yandex.ru>,       Darima       Kogan
       <silverdk99@gmail.com>,  Max  Is  <ismax799@gmail.com>,  Yuri  Kozlov  <yuray@komyakino.ru>,  Иван Павлов
       <pavia00@gmail.com> и Kirill Rekhov <krekhov.dev@gmail.com>

       Этот перевод является свободной программной документацией; он распространяется на условиях  общедоступной
       лицензии  GNU  (GNU  General Public License - GPL, https://www.gnu.org/licenses/gpl-3.0.html версии 3 или
       более поздней) в отношении авторского права, но БЕЗ КАКИХ-ЛИБО ГАРАНТИЙ.

       Если вы обнаружите какие-либо ошибки в переводе этой страницы руководства, пожалуйста, сообщите  об  этом
       разработчику(ам)   по   его(их)  адресу(ам)  электронной  почты  или  по  адресу  списка рассылки русских
       переводчиков.

Справочные страницы Linux 6.9.1                   2 мая 2024 г.                                pthread_atfork(3)