Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A python script doing the same operations as cgroup_event_listener.c
# Usage: sudo python /sys/fs/cgroup/memory/hoge/memory.usage_in_bytes 263M
import sys
import os, os.path
import struct
import linux
def main():
target_file = sys.argv[1]
threshold = sys.argv[2]
# Don't write in one call chain to keep open the fd
f = open(target_file)
cfd = f.fileno()
event_file = os.path.join(os.path.dirname(target_file),
event_control = open(event_file, 'w')
ecfd = event_control.fileno()
efd = linux.eventfd(0, 0)
line = "%d %d %s\0"%(efd,cfd,threshold)
os.write(ecfd, line)
while True:
ret =, 64/8)
ret = struct.unpack('Q', ret)
if ret == -1:
print('Cannot read from eventfd')
if not os.path.exists(event_file):
print('The cgroup seems to have removed.')
print("%s %s: crossed"%(target_file,threshold))
if __name__ == "__main__":
Copy link

joemiller commented Aug 13, 2012

where can i find that 'linux' module?


Copy link

sfriesel commented Jan 21, 2013 you have to compile it yourself though.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment