コード例 #1
0
    def test_ps_table(self):
        cg_path = create_random_cg(self.parent_cg_path)
        multithead_sleep = "\n".join([
            'import time, threading',
            't = threading.Thread(target=time.sleep, args=(10,))',
            't.start()',
            't.join()'
        ])
        subprocess.Popen(["sudo", "cgexec", "-g",
                          descriptor_from_cg_path(cg_path),
                          "sh", "-c", "sleep 10"])
        subprocess.Popen(["sudo", "cgexec", "-g",
                          descriptor_from_cg_path(cg_path),
                          "python", "-c", multithead_sleep])

        time.sleep(2)  # Sleep for a little bit to let them spawn
        cg = Cgroup(cg_path)
        table = cg.ps_table()

        # We should see 3 processes (but there are 4 threads here)
        self.assertEqual(3, len(table))
        by_name = {proc["name"]: proc for proc in table}
        self.assertEqual(["python", "sh", "sleep"], sorted(by_name.keys()))

        for name in ["sh", "sleep"]:
            proc = by_name[name]
            self.assertIsInstance(proc["pid"], int)
            self.assertIsInstance(proc["memory_info"].vms, int)
            self.assertIsInstance(proc["memory_info"].rss, int)
            self.assertIsInstance(proc["cmdline"], list)
            self.assertIn(proc["status"], PROC_STATUSES_RAW.keys())
コード例 #2
0
    def test_ps_table(self):
        cg_path = create_random_cg(self.parent_cg_path)
        subprocess.Popen([
            "sudo", "cgexec", "-g",
            descriptor_from_cg_path(cg_path), "sh", "-c", "sleep 10"
        ])
        time.sleep(2)  # Sleep for a little bit to let them spawn
        cg = Cgroup(cg_path)
        table = cg.ps_table()

        self.assertEqual(2, len(table))
        by_name = {proc["name"]: proc for proc in table}
        self.assertEqual(["sh", "sleep"], sorted(by_name.keys()))

        for name in ["sh", "sleep"]:
            proc = by_name[name]
            self.assertIsInstance(proc["pid"], int)
            self.assertIsInstance(proc["memory_info"].vms, int)
            self.assertIsInstance(proc["memory_info"].rss, int)
            self.assertIsInstance(proc["cmdline"], list)
            self.assertIn(proc["status"], PROC_STATUSES_RAW.keys())