my $tfd = Linux::Perl::timerfd->new(
        clockid => 'REALTIME',
        flags => [ 'NONBLOCK', 'CLOEXEC' ],

    #or, e.g., Linux::Perl::timerfd::x86_64

    my $fd = $tfd->fileno();

    ($old_interval, $old_value) = $tfd->settime(
        interval => $interval_seconds,
        value    => $value_seconds,
        flags    => [ 'ABSTIME', 'CANCEL_ON_SET' ],

    my ($interval, $value) = $tfd->gettime();


    my $read = $tfd->read();


This is an interface to the timerfd_* family of system calls.

This class inherits from Linux::Perl::Base::TimerEventFD.


CLASS->new( %OPTS )

%OPTS is:

  • clockid - One of: REALTIME, MONOTONIC, BOOTTIME, REALTIME_ALARM, or BOOTTIME_ALARM. Not all kernel versions support all of these; check man 2 timerfd_create for your system.

  • flags - Optional, an array reference of any or all of: NONBLOCK, CLOEXEC.

    This follows the same practice as Linux::Perl::eventfd regarding CLOEXEC and $^F.

$OBJ = OBJ->settime( %OPTS )

($old_interval, $old_value) = OBJ->settime( %OPTS )

See man 2 timerfd_settime for details about what this does.

%OPTS is:

  • value - in seconds.

  • interval - in seconds. Must be falsy if value is falsy. (Rationale: timerfd_settime will ignore interval if value is zero. This seems unintuitive, so we avoid that situation altogether.)

  • flags - Optional, arrayref. Accepted values are ABSTIME and CANCEL_ON_SET. Your kernel may not support all of these; check man 2 timerfd_settime for details.

In scalar context this returns the object. This facilitates easy setting of the value on instantiation.

In list context it returns the previous interval and value.

($old_interval, $old_value) = OBJ->gettime()

Returns the old interval and value, in seconds.

my $ok_yn = OBJ->set_ticks( $NUM_TICKS )

See man 2 timerfd_create (look for TFD_IOC_SET_TICKS) for details on what this does.

This returns truthy if the operation succeeded and falsy if the system does not support this operation. (Any other failure will prompt an exception to be thrown.)

$expirations = OBJ->read()

See man 2 timerfd_create for details on what this returns. Sets $! and returns undef on error.