<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "System",
  "identifier" : "/documentation/System/FileDescriptor/DuplicateOptions/closeOnFork",
  "metadataVersion" : "0.1.0",
  "role" : "Type Property",
  "symbol" : {
    "kind" : "Type Property",
    "modules" : [
      "System"
    ],
    "preciseIdentifier" : "s:6System14FileDescriptorV16DuplicateOptionsV11closeOnForkAEvpZ"
  },
  "title" : "closeOnFork"
}
-->

# closeOnFork

Indicates that forking a program closes the file.

```
static var closeOnFork: FileDescriptor.DuplicateOptions { get }
```

## Discussion

Normally, file descriptors remain open
across calls to the `fork(2)` function.
If you specify this option,
the file descriptor is closed when forking this process
into another process.

The state of the file
descriptor flags can be inspected using `F_GETFD`,
as described in the `fcntl(2)` man page.

The corresponding C constant is `O_CLOFORK`.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)