---
name: "POSIX::AtFork"
section: "3pm"
platform: "linux"
package: "libposix-atfork-perl"
version: "0.04-2+b5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/POSIX::AtFork"
---

# POSIX::AtFork(3pm)

Hook registrations at fork(2)

## NAME

POSIX::AtFork - Hook registrations at [fork(2)](/fork/2.md)

## SYNOPSIS

```
  # POSIX interface:
  use POSIX::AtFork qw(:all);

  pthread_atfork(\&prepare, \&parent, \&child);
  # or per-hook interfaces:
  POSIX::AtFork->add_to_prepare(\&prepare);
  POSIX::AtFork->add_to_parent(\&parent);
  POSIX::AtFork->add_to_child(\&child);
  # registered callbacks can be removed
  POSIX::AtFork->delete_from_prepare(\&prepare);
  POSIX::AtFork->delete_from_parent( \&parent);
  POSIX::AtFork->delete_from_child(  \&child);
```

## DESCRIPTION

This module is an interface to `pthread_atfork(3)`, which registeres handlers called before and after `fork(2)`.

## INTERFACE

### pthread\_atfork(\\&prepare, \\&parent, \\&child)

Registeres hooks called before `fork()` (*&prepare*) and after (*&parent* for the parent, *&child* for the child).

All callbacks are called with the current opname, namely `"fork"`, `"system"`, `"backtick"`, and etc.

This exportable function is an interface to `pthread_atfork(3)`.

### POSIX::AtFork-\>add\_to\_prepare(\\&hook)

The same as `"pthread_atfork(\&hook, undef, undef)"`.

### POSIX::AtFork-\>add\_to\_parent(\\&hook)

The same as `"pthread_atfork(undef, \&hook, undef)"`.

### POSIX::Atfork-\>add\_to\_child(\\&hook)

The same as `"pthread_atfork(undef, undef, \&hook)"`.

### POSIX::AtFork-\>delete\_from\_prepare(\\&hook)

Deletes *&hook* from the `"prepare"` hook list.

### POSIX::AtFork-\>delete\_from\_parent(\\&hook)

Deletes *&hook* from the `"parent"` hook list.

### POSIX::AtFork-\>delete\_from\_child(\\&hook)

Deletes *&hook* from the `"child"` hook list.

## SEE ALSO

[**pthread\_atfork**(3)](/pthread_atfork/3.md)

[**fork**(2)](/fork/2.md)

## AUTHORS

Fuji, Goro (gfx)

Shulyakovskiy, Nikolay (nikolas)

## COPYRIGHT AND LICENSE

Copyright (C) 2010 by Fuji, Goro gfx \<gfuji@cpan.org\>.

Copyright (C) 2020 by Shulyakovskiy, Nikolay nikolas \<nikolas@cpan.org\>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself,
