public static List < Integer > getOldPortPids ( String port ) { String currPid = JStormUtils . process_pid ( ) ; List < Integer > ret = new ArrayList <> ( ) ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( "ps -Af " ) ; // sb.append(" | grep "); // sb.append(Worker.class.getName()); // sb.append(" |grep "); // sb.append(port); // sb.append(" |grep -v grep"); try { LOG . info ( "Begin to execute " + sb . toString ( ) ) ; String output = JStormUtils . launchProcess ( sb . toString ( ) , new HashMap < String , String > ( ) , false ) ; BufferedReader reader = new BufferedReader ( new StringReader ( output ) ) ; JStormUtils . sleepMs ( 1000 ) ; // if (process.exitValue() != 0) { // LOG.info("Failed to execute " + sb.toString()); // return null; // } String str ; while ( ( str = reader . readLine ( ) ) != null ) { if ( StringUtils . isBlank ( str ) ) { // LOG.info(str + " is Blank"); continue ; } // LOG.info("Output:" + str); if ( ! str . contains ( Worker . class . getName ( ) ) ) { continue ; } else if ( str . contains ( ProcessLauncher . class . getName ( ) ) ) { continue ; } else if ( ! str . contains ( port ) ) { continue ; } LOG . info ( "Find :" + str ) ; String [ ] fields = StringUtils . split ( str ) ; boolean find = false ; int i = 0 ; for ( ; i < fields . length ; i ++ ) { String field = fields [ i ] ; LOG . debug ( "Found, " + i + ":" + field ) ; if ( field . contains ( Worker . class . getName ( ) ) ) { if ( i + 3 >= fields . length ) { LOG . info ( "Failed to find port " ) ; } else if ( fields [ i + 3 ] . equals ( String . valueOf ( port ) ) ) { find = true ; } break ; } } if ( ! find ) { LOG . info ( "No old port worker" ) ; continue ; } if ( fields . length >= 2 ) { try { if ( currPid . equals ( fields [ 1 ] ) ) { LOG . info ( "Skip killing myself" ) ; continue ; } Integer pid = Integer . valueOf ( fields [ 1 ] ) ; LOG . info ( "Find one process :" + pid . toString ( ) ) ; ret . add ( pid ) ; } catch ( Exception e ) { LOG . error ( e . getMessage ( ) , e ) ; } } } return ret ; } catch ( IOException e ) { LOG . info ( "Failed to execute " + sb . toString ( ) ) ; return ret ; } catch ( Exception e ) { LOG . info ( e . getMessage ( ) , e ) ; return ret ; } }
Note that if the worker s start parameter length is longer than 4096 ps - ef|grep com . alibaba . jstorm . daemon . worker . Worker can t find worker