From ddc4d50b77532568bb6aabd7cff68a162229a8f1 Mon Sep 17 00:00:00 2001 From: Gerard Wagener Date: Mon, 18 Jan 2010 09:35:38 +0100 Subject: [PATCH] Remove processes from the system from the processtree Purpose: Avoid that process tree grows too much --- aha/ahalib.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/aha/ahalib.py b/aha/ahalib.py index af9adcd7fa0..0228a4b215a 100644 --- a/aha/ahalib.py +++ b/aha/ahalib.py @@ -119,8 +119,12 @@ class ProcessTrees: pass def searchTree(self,pid,ppid): + #Make sure that pid is different from ppid -> to avoid recursion error self.foundUser = 0 self.__searchTree(pid,ppid) + #If the process belongs to the system remove it, to free up memory + if self.foundUser == False: + self.processList.pop(pid) return self.foundUser @@ -166,6 +170,26 @@ class TestProcessTree(unittest.TestCase): ret = x.searchTree(2008,2007) self.assertEqual(ret,1) + def testCleanUp(self): + x = ProcessTrees() + #Init is executed + ret = x.searchTree(1,0) + self.assertEqual(ret,0) + print x.processList + self.assertEqual(len(x.processList.keys()),0) + + def testMixCleanUp(self): + x = ProcessTrees() + x.addUser(123) + ret = x.searchTree(444,123) + self.assertEqual(ret,1) + self.assertEqual(len(x.processList.keys()),1) + #System adds a process the process vector should not grow + #Process 555 does not exits + ret = x.searchTree(333,555) + self.assertEqual(ret,0) + self.assertEqual(len(x.processList.keys()),1) + if __name__ == '__main__': unittest.main()