Is there a way, in Linux or FreeBSD, to receive notification from system at a specified time? I'm thinking something in like of what inotify in Linux does for filesystem events.

There IS a way to that using cron, but I'm asking if there is a lower-level interface that can be called programatically. If cron is an 'official' Unix interface for this kind of task, I'd like to know that, too.

  • 1
    Have you looked at at? – Joseph R. Aug 22 '13 at 11:31
  • 1
    cron is 'official' – innocent-world Aug 22 '13 at 11:51
  • @Joseph R. I did, but as I say in the question, i look for way to do it from code. Wrapping executable doesn't do it. – Red Aug 22 '13 at 15:43
  • @Red Are we talking shell code or are you looking for a C API? – Joseph R. Aug 22 '13 at 15:45

There are two low level interfaces that I'm aware of:

One is simply to do a sleep() until that moment when you want to receive the notification. The sleep call is provided by glibc.

The other method would be the alarm() system call. It allows you to tell the kernel that after a defined amount of time has passed it should send the calling process a SIGALRM. It's very likely that you'll have to create an appropriate signal handler which then does what you want to do.

For both of these two approaches you can't set the absolute time when you want to get notified. Instead you will have to get the current time, and calculate based on it for how long your process has to wait until it should be awaken or alarmed.

References (on Linux): man 3 sleep; man 2 alarm;

  • alarm() is exactly what I was looking for. To complement your answer, in newest FreeBSD it's deprecated in favor of setitimer(). – Red Aug 22 '13 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.