Show Table of Contents
2.13. Using the Notification API
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:
- Using the
eventfd()function, create a file descriptor for event notifications. For more information, refer to theeventfd(2)man page. - To monitor the
memory.oom_controlfile, open it using theopen()function. For more information, refer to theopen(2)man page. - Use the
write()function to write the following arguments to thecgroup.event_controlfile of the cgroup whosememory.oom_controlfile you are monitoring:<event_file_descriptor> <OOM_control_file_descriptor>
where:- event_file_descriptor is used to open the
cgroup.event_controlfile, - and OOM_control_file_descriptor is used to open the respective
memory.oom_controlfile.
For more information on writing to a file, refer to thewrite(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.
For more information on the
memory.oom_control tunable parameter, refer to Section 3.7, “memory”. For more information on configuring notifications for OOM control, refer to Example 3.3, “OOM Control and Notifications”.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.