#!/usr/bin/env python3

import os
import sys
import subprocess


def enter_cgroup():
    cgroup = '/sys/fs/cgroup/memory/chrome/tasks'

    if os.path.exists(cgroup):
        with open(cgroup, 'w') as f:
            f.write(str(os.getpid()))


# Kill any existing Chromium process first
# Note, "chromium-browse" is intentional
subprocess.Popen(['killall', 'chromium-browse']).wait()

# Start browser
args = ['/usr/lib/chromium-browser/chromium-browser'] + sys.argv[1:]
subprocess.Popen(args, preexec_fn = enter_cgroup).wait()
