Change in vdsm[master]: make misc.pgrep for general usage
lvroyce at linux.vnet.ibm.com
lvroyce at linux.vnet.ibm.com
Tue Jan 15 10:41:52 UTC 2013
Royce Lv has uploaded a new change for review.
Change subject: make misc.pgrep for general usage
......................................................................
make misc.pgrep for general usage
pgrep now just grep specific named process,
Make it accept other params(e.g.ppid, state, etc)
for general usage.
Change-Id: I2034b04a4787d2f222cb98dfe3ffcdbb2a94ebb8
Signed-off-by: Royce Lv<lvroyce at linux.vnet.ibm.com>
---
M tests/miscTests.py
M vdsm/storage/misc.py
2 files changed, 21 insertions(+), 4 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/33/11033/1
diff --git a/tests/miscTests.py b/tests/miscTests.py
index a949a09..885b913 100644
--- a/tests/miscTests.py
+++ b/tests/miscTests.py
@@ -63,7 +63,7 @@
class PgrepTests(TestCaseBase):
- def test(self):
+ def testGrepName(self):
sleepProcs = []
for i in range(3):
sleepProcs.append(misc.execCmd([EXT_SLEEP, "3"], sync=False,
@@ -78,6 +78,21 @@
proc.kill()
proc.wait()
+ def testGrepPpid(self):
+ sleepProcs = []
+ for i in range(3):
+ sleepProcs.append(misc.execCmd([EXT_SLEEP, "3"], sync=False,
+ sudo=False))
+
+ pids = misc.pgrep(os.getpid(), 'ppid')
+ for proc in sleepProcs:
+ self.assertTrue(proc.pid in pids, "pid %d was not located by pgrep"
+ % proc.pid)
+
+ for proc in sleepProcs:
+ proc.kill()
+ proc.wait()
+
class GetCmdArgsTests(TestCaseBase):
def test(self):
diff --git a/vdsm/storage/misc.py b/vdsm/storage/misc.py
index 5ec13e4..2438335 100644
--- a/vdsm/storage/misc.py
+++ b/vdsm/storage/misc.py
@@ -1109,8 +1109,10 @@
yield int(pid)
-def pgrep(name):
+def pgrep(statValue, statKey='name'):
res = []
+ statMap = {'name': 1, 'state': 2, 'ppid': 3}
+ statIndex = statMap.get(statKey, 1)
for pid in iteratePids():
try:
pid = int(pid)
@@ -1118,8 +1120,8 @@
continue
try:
- procName = utils.pidStat(pid)[1]
- if procName == name:
+ watchedStat = utils.pidStat(pid)[statIndex]
+ if watchedStat == statValue:
res.append(pid)
except (OSError, IOError):
continue
--
To view, visit http://gerrit.ovirt.org/11033
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2034b04a4787d2f222cb98dfe3ffcdbb2a94ebb8
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Royce Lv <lvroyce at linux.vnet.ibm.com>
More information about the vdsm-patches
mailing list