mirror of
https://github.com/adulau/aha.git
synced 2024-12-26 18:56:14 +00:00
Remove processes from the system from the processtree
Purpose: Avoid that process tree grows too much
This commit is contained in:
parent
912fb42b02
commit
ddc4d50b77
1 changed files with 24 additions and 0 deletions
|
@ -119,8 +119,12 @@ class ProcessTrees:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def searchTree(self,pid,ppid):
|
def searchTree(self,pid,ppid):
|
||||||
|
#Make sure that pid is different from ppid -> to avoid recursion error
|
||||||
self.foundUser = 0
|
self.foundUser = 0
|
||||||
self.__searchTree(pid,ppid)
|
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
|
return self.foundUser
|
||||||
|
|
||||||
|
|
||||||
|
@ -166,6 +170,26 @@ class TestProcessTree(unittest.TestCase):
|
||||||
ret = x.searchTree(2008,2007)
|
ret = x.searchTree(2008,2007)
|
||||||
self.assertEqual(ret,1)
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue