NIFI-215: Look for the pid in the output of the ps command and do not use the 
--no-headers argument because it's not compatible with OSX


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

Branch: refs/heads/develop
Commit: 0297fa465f230028ca83f8a4d573de185fe79f5f
Parents: d879e0d
Author: Mark Payne <marka...@hotmail.com>
Authored: Wed Dec 31 08:24:44 2014 -0500
Committer: Mark Payne <marka...@hotmail.com>
Committed: Wed Dec 31 08:24:44 2014 -0500

----------------------------------------------------------------------
 .../main/java/org/apache/nifi/bootstrap/RunNiFi.java | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/0297fa46/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java
----------------------------------------------------------------------
diff --git 
a/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java 
b/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java
index 0f97f2d..e8f6439 100644
--- a/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java
+++ b/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java
@@ -294,25 +294,24 @@ public class RunNiFi {
                // We use the "ps" command to check if the process is still 
running.
                final ProcessBuilder builder = new ProcessBuilder();
                
-               builder.command("ps", "-p", pid, "--no-headers");
+               builder.command("ps", "-p", pid);
                final Process proc = builder.start();
                
-               // Read how many lines are output by the 'ps' command
-               int lineCount = 0;
+               // Look for the pid in the output of the 'ps' command.
+               boolean running = false;
                String line;
                try (final InputStream in = proc.getInputStream();
                     final Reader streamReader = new InputStreamReader(in);
                     final BufferedReader reader = new 
BufferedReader(streamReader)) {
                    
                    while ((line = reader.readLine()) != null) {
-                       if ( !line.trim().isEmpty() ) {
-                           lineCount++;
-                       }
+                    if ( line.trim().startsWith(pid) ) {
+                        running = true;
+                    }
                    }
                }
                
-               // If anything was output, the process is running.
-               final boolean running = lineCount > 0;
+               // If output of the ps command had our PID, the process is 
running.
                if ( running ) {
                    logger.fine("Process with PID " + pid + " is running");
                } else {

Reply via email to