Книга: Programming with POSIX® Threads
9.3.9 Fork handlers
9.3.9 Fork handlers
Pthreads provides some new functions to help the new threaded environment to coexist with the traditional process-based UNIX environment. Creation of a child process by copying the full address space, for example, causes problems for threaded applications because the fork call is asynchronous with respect to other threads in the process.
pthread_atfork
int pthread_atfork (
void (*prepare)(void),
void (*parent)(void),
void (*child)(void));
Define "fork handlers" that are run when the process creates a child process. Allows protection of synchronization objects and shared data in the child process (which is otherwise difficult to control).
References: 6.1.1
Headers: <unistd.h>*[10]
Errors: [ENOMEM] insufficient space to record the handlers.
Hint: All resources needed by child must be protected.
- 6.1 fork
- 6.1.1 Fork handlers
- 10.5.1 Installing Exception Handlers
- 10.5.3 Loading and Invoking Exception Handlers
- 10.5.5 Exception Handlers
- Wiring All the Event Handlers
- Листинг 3.3. (fork.c) Ветвление программы с помощью функции fork()
- 9.1.1. Создание процесса: fork()
- 9.1.1.1. После fork(): общие и различные атрибуты
- 10.9. Сигналы, передающиеся через fork() и exec()
- Вызов функции fork()