<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "System",
  "identifier" : "/documentation/System/FileDescriptor/OpenOptions/closeOnExec",
  "metadataVersion" : "0.1.0",
  "role" : "Type Property",
  "symbol" : {
    "kind" : "Type Property",
    "modules" : [
      "System"
    ],
    "preciseIdentifier" : "s:6System14FileDescriptorV11OpenOptionsV11closeOnExecAEvpZ"
  },
  "title" : "closeOnExec"
}
-->

# closeOnExec

Indicates that executing a program closes the file.

```
static var closeOnExec: FileDescriptor.OpenOptions { get }
```

## Discussion

Normally, file descriptors remain open
across calls to the `exec(2)` family of functions.
If you specify this option,
the file descriptor is closed when replacing this process
with 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_CLOEXEC`.

---

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)