GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
EVENTFD(2) FreeBSD System Calls Manual EVENTFD(2)

eventfd
create a file descriptor for event notification

Standard C Library (libc, -lc)

#include <sys/eventfd.h>

int
eventfd(unsigned int initval, int flags);

int
eventfd_read(int fd, eventfd_t *value);

int
eventfd_write(int fd, eventfd_t value);

eventfd() creates a special file descriptor with event counter or semaphore semantics, designed for interprocess communication. The returned file descriptor refers to a kernel object containing an unsigned 64-bit integer counter, which is initialized with the value of the initval argument.

The flags argument may contain the result of or'ing the following values:

set FD_CLOEXEC on the file descriptor
do not block on read/write operations
use semaphore semantics

File operations have the following semantics:

read(2)
If the counter is zero, the call blocks until the counter becomes non-zero, unless EFD_NONBLOCK was set, in which case it would fail with EAGAIN instead.

If the counter is non-zero:

  • If EFD_SEMAPHORE is not set, the current value of the counter is returned, and the value is reset to zero.
  • If EFD_SEMAPHORE is set, the constant 1 is returned, and the value is decremented by 1.

The numeric value is encoded as 64-bit (8 bytes) in host byte order. The read(2) call fails with EINVAL if there is less than 8 bytes available in the supplied buffer.

write(2)
Adds the given value to the counter. The maximum value that can be stored in the counter is the maximum unsigned 64-bit integer value minus one (0xfffffffffffffffe).

If the resulting value exceeds the maximum, the call would block until the value is reduced by read(2), unless EFD_NONBLOCK was set, in which case it would fail with EAGAIN instead.

The numeric value is encoded as 64-bit (8 bytes) in host byte order. The write(2) call fails with EINVAL if there is less than 8 bytes available in the supplied buffer, or if the value 0xffffffffffffffff is given.

poll(2)
When receiving notifications via poll(2) / ppoll(2) / select(2) / pselect(2) / kqueue(2), the following semantics apply:
  • The file descriptor is readable when the counter is greater than zero.
  • The file descriptor is writable when the counter is less than the maximum value.

File descriptors created by eventfd() are passable to other processes via sendmsg(2) and are preserved across fork(2); in both cases the descriptors refer to the same counter from both processes. Unless O_CLOEXEC flag was specified, the created file descriptor will remain open across execve(2) system calls; see close(2), fcntl(2) and O_CLOEXEC description.

eventfd_read() and eventfd_write() are thin wrappers around read(2) and write(2) system calls, provided for compatibility with glibc.

If successful, eventfd() returns a non-negative integer, termed a file descriptor. It returns -1 on failure, and sets errno to indicate the error.

The eventfd_read() and eventfd_write() functions return 0 if the operation succeeded, -1 otherwise.

eventfd() may fail with:
[]
The flags argument given to eventfd() has unknown bits set.
[]
The process has already reached its limit for open file descriptors.
[]
The system file table is full.
[]
No memory was available to create the kernel object.

close(2), kqueue(2), poll(2), read(2), select(2), write(2)

The eventfd() system call is non-standard. It is present in Linux.

The eventfd() system call first appeared in FreeBSD 13.0.
October 8, 2020 FreeBSD 13.1-RELEASE

Search for    or go to Top of page |  Section 2 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.