diff --git a/src/pty.c b/src/pty.c
index 11dbe6a..44b0222 100644
--- a/src/pty.c
+++ b/src/pty.c
@@ -1,3 +1,5 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: t -*-*/
+
 /*
  * Copyright (C) 2001,2002 Red Hat, Inc.
  * Copyright © 2009, 2010 Christian Persch
@@ -58,6 +60,7 @@
 #include <stropts.h>
 #endif
 #include <glib.h>
+#include <glib/gstdio.h>
 #include <gio/gio.h>
 #include "debug.h"
 #include "pty.h"
@@ -307,6 +310,68 @@ vte_pty_child_setup (VtePty *pty)
 	}
 #endif
 
+#ifdef __linux__
+{
+	char *cgroup;
+
+	/* On Linux, let's create a subgroup in the CPU cgroup
+	 * hierarchy for our child, if this features is available in
+	 * the kernel and we have the permissions to do this. For this
+	 * we first figure out the group we ourselves are running in
+	 * and then create a child named after our pid beneath it.
+	 *
+	 * This code assumes that procfs is mounted /proc, and the cpu
+	 * cgroup hierarchy to /sys/fs/cgroup/cpu, which are the
+	 * standard places for these fsh these days. */
+
+	if (g_file_get_contents("/proc/self/cgroup", &cgroup, NULL, NULL)) {
+		char *p = cgroup;
+
+		while (*p) {
+			/* Skip initial integer */
+			p += strcspn(p, ":");
+
+			if (g_str_has_prefix(p, ":cpu:/"))
+				break;
+
+			/* Skip to end of line */
+			p += strcspn(p, "\n");
+			p += strspn(p, "\n");
+		}
+
+		if (*p) {
+			char *subgroup, *tasks;
+			FILE *f;
+			pid_t pid;
+
+			p += 5;
+
+			/* Truncate at newline */
+			p[strcspn(p, "\n")] = 0;
+
+			pid = getpid();
+
+			/* We don't really care for errors here, if it
+			 * fails it fails.  */
+			subgroup = g_strdup_printf("/sys/fs/cgroup/cpu%s/vte-%lu", p, (unsigned long) pid);
+			g_mkdir(subgroup, 0755);
+			g_free(subgroup);
+
+			tasks = g_strdup_printf("/sys/fs/cgroup/cpu%s/vte-%lu/tasks", p, (unsigned long) pid);
+
+			if ((f = fopen(tasks, "we"))) {
+				fprintf(f, "%lu\n", (unsigned long) pid);
+				fclose(f);
+			}
+
+			g_free(tasks);
+		}
+
+		g_free(cgroup);
+	}
+}
+#endif
+
 	/* now setup child I/O through the tty */
 	if (fd != STDIN_FILENO) {
 		if (dup2(fd, STDIN_FILENO) != STDIN_FILENO){
