Skip to content
BSD syscall#6

svc · unix #6

close

Releases a file descriptor and decrements the reference count on the underlying open-file table entry.

Prototype

int close(int fd);

Returns: int

Arguments

NameTypeDirDescription
fdint-

Version history

XNU tagmacOS#
xnu-1456.1.26macOS 10.6 Snow Leopard6
xnu-1699.24.8macOS 10.7 Lion6
xnu-2050.18.24macOS 10.8 Mountain Lion6
xnu-2422.115.4macOS 10.9 Mavericks6
xnu-2782.40.9macOS 10.10 Yosemite6
xnu-3247.1.106macOS 10.11 El Capitan6
xnu-3789.1.32macOS 10.12 Sierra6
xnu-4570.1.46macOS 10.13 High Sierra6
xnu-4903.221.2macOS 10.14 Mojave6
xnu-6153.11.26macOS 10.15 Catalina6
xnu-1486.2.116
xnu-1504.15.36
xnu-1504.3.126
xnu-1504.7.46
xnu-1504.9.176
xnu-1504.9.266
xnu-1504.9.376
xnu-1699.22.736
xnu-1699.22.816
xnu-1699.24.236
xnu-1699.26.86
xnu-1699.32.76
xnu-2050.22.136
xnu-2050.24.156
xnu-2050.48.116
xnu-2050.7.96
xnu-2050.9.26
xnu-2422.1.726
xnu-2422.100.136
xnu-2422.110.176
xnu-2422.90.206
xnu-2782.1.976
xnu-2782.10.726
xnu-2782.20.486
xnu-2782.30.56
xnu-3247.10.116
xnu-3248.20.556
xnu-3248.30.46
xnu-3248.40.1846
xnu-3248.50.216
xnu-3248.60.106
xnu-3789.21.46
xnu-3789.31.26
xnu-3789.41.36
xnu-3789.51.26
xnu-3789.60.246
xnu-3789.70.166
xnu-4570.20.626
xnu-4570.31.36
xnu-4570.41.26
xnu-4570.51.16
xnu-4570.61.16
xnu-4570.71.26
xnu-4903.231.46
xnu-4903.241.16
xnu-4903.270.476
xnu-6153.101.66
xnu-6153.121.16
xnu-6153.141.16
xnu-6153.41.36
xnu-6153.61.16
xnu-6153.81.56

Examples

C — close after use

close(fd);

Notes

The kernel removes the fd from the process file table and drops a reference on the fileglob. When the last reference disappears the vnode is inactivated, pending writes are flushed and any advisory locks held on the file are released. Closing a guarded descriptor without close_guard set is rejected with EBADF.

Detection

Endpoint Security emits ES_EVENT_TYPE_NOTIFY_CLOSE with the vnode being released. DTrace's syscall::close:entry/return fires per invocation; fs.fileops kernel probes capture the vnode reference drop.

Related APIs

opendupdup2guarded_close_npfcntlopenat