The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.




  # Process 1- waits to be notified and then performs work
  my $notify = IPC::Notify->new("/path/to/lock");
  for (;;) {
    # do work
    print "I am doing some work!\n";

  # Process 2- wakes up process 1
  my $notify = IPC::Notify->new("/path/to/lock");


new() - create a new notify locking object

  my $notify = IPC::Notify->new($filename);


is_locked() - check whether object is currently "locked"

  if ($notify->is_locked) { ... }

Returns nonzero if the object is currently locked.

lock() - obtain a file lock


A lock must be acquired before using wait() or notify() on this object. This ensures proper synchronization. This method will block if another (non-waiting) process has the lock.

notify() - wake up all processes waiting on this lock


This will wake up all processes waiting on the lock, however, you need to call unlock() from the notifying process before the other process(es) will be allowed to proceed.

wait() - wait for a notification on this lock


This method will atomically give up the lock this process has on the object and wait for a notification. Before returning control, it will re-acquire the lock.

If $timeout_in_seconds is specified, wait() will return control early if a notification is not received within the specified time. Fractional values are acceptable.

If $timeout_in_seconds is absent, or "undef", then it will wait forever. If $timeout_in_seconds is zero, the call will be nonblocking. (It will simply indicate whether a notification has been received.)

The result is nonzero if a notification was received. Otherwise, the timeout had elapsed.

unlock() - release a lock


Be sure to unlock() if you are going to do some other work. As long as one process holds the lock, other processes will block to notify().