You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2014/07/25 19:57:04 UTC

[08/11] git commit: Use alternative approach to find unused PID.

Use alternative approach to find unused PID.

ps ax appears to fail on builds.apache.org, use alternative
approach of finding an unused PID which even is more effective.


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/a40e55b7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/a40e55b7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/a40e55b7

Branch: refs/heads/master
Commit: a40e55b7266cf1e2150dabd0cbbd5eb6a7e4b2d4
Parents: a1cead9
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Fri Jul 25 11:58:30 2014 +0300
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Fri Jul 25 11:58:30 2014 +0300

----------------------------------------------------------------------
 .../java/brooklyn/qa/longevity/MonitorUtilsTest.java   | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a40e55b7/usage/qa/src/test/java/brooklyn/qa/longevity/MonitorUtilsTest.java
----------------------------------------------------------------------
diff --git a/usage/qa/src/test/java/brooklyn/qa/longevity/MonitorUtilsTest.java b/usage/qa/src/test/java/brooklyn/qa/longevity/MonitorUtilsTest.java
index e2b9d1f..b43df13 100644
--- a/usage/qa/src/test/java/brooklyn/qa/longevity/MonitorUtilsTest.java
+++ b/usage/qa/src/test/java/brooklyn/qa/longevity/MonitorUtilsTest.java
@@ -91,16 +91,11 @@ public class MonitorUtilsTest {
     public void testIsPidRunning() throws Exception {
         int usedPid = MonitorUtils.findOwnPid();
 
-        // Find a pid that is in not in use
-        // Don't count upwards as that is more likely to be the next pid to be allocated leading to non-deterministic failures!
-        // 10000 is a conservative estimate of a legal large pid (/proc/sys/kernel/pid_max gives the real max)
-        Process process = MonitorUtils.exec("ps ax");
+        //the child process will terminate freeing it PID
+        String[] cmd = new String[]{"bash", "-c", "echo $$"};
+        Process process = Runtime.getRuntime().exec(cmd);
         String out = MonitorUtils.waitFor(process);
-        int unusedPid = 10000;
-        while (out.contains(""+unusedPid)) {
-            unusedPid--;
-        }
-        if (unusedPid <= 0) throw new IllegalStateException("No unused pid found in the range 1-10000");
+        int unusedPid = Integer.parseInt(out.trim());
 
         assertTrue(MonitorUtils.isPidRunning(usedPid));
         assertFalse(MonitorUtils.isPidRunning(unusedPid));