The cgroups notification API allows user space applications to receive notifications about the changing status of a cgroup. Currently, the notification API only supports monitoring of the Out of Memory (OOM) control file:
memory.oom_control. To create a notification handler, write a C program using the following instructions:
eventfd() function, create a file descriptor for event notifications. For more information, refer to the
eventfd(2) man page.
To monitor the
memory.oom_control file, open it using the
open() function. For more information, refer to the
open(2) man page.
write() function to write the following arguments to the
cgroup.event_control file of the cgroup whose
memory.oom_control file you are monitoring:
event_file_descriptor is used to open the
and OOM_control_file_descriptor is used to open the respective
For more information on writing to a file, refer to the
write(1) man page.
When the above program is started, it will be notified of any OOM situation in the cgroup it is monitoring. Note that OOM notifications only work in non-root cgroups.