Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Tested with windows <code>Tasklist</code> command, you try with linux command.</p> <pre><code>public class ProcessListTable { private String GetProcessListData() { Process p; Runtime runTime; String process = null; try { System.out.println("Processes Reading is started..."); //Get Runtime environment of System runTime = Runtime.getRuntime(); //Execute command thru Runtime // use appropriate command for linux "ps" p = runTime.exec("tasklist /FO CSV /nh"); //Create Inputstream for Read Processes InputStream inputStream = p.getInputStream(); InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); ArrayList&lt;String&gt; taskEntries = new ArrayList(); String line = bufferedReader.readLine(); while (line != null) { taskEntries.add(line); line = bufferedReader.readLine(); } bufferedReader.close(); inputStreamReader.close(); inputStream.close(); MyTableModel myTableModel = new MyTableModel(); myTableModel.update(taskEntries); JTable table = new JTable(myTableModel); JFrame frame = new JFrame("TaskList"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.add(new JScrollPane(table)); frame.pack(); frame.setVisible(true); System.out.println("Processes are read."); } catch (IOException e) { System.out.println("Exception arise during the read Processes"); e.printStackTrace(); } return process; } public class MyTableModel extends AbstractTableModel { String[] columnName = new String[]{"Image Name", "PID", "Session Name", "Session#", "Mem Usage"}; String[][] valueA; public void update(ArrayList&lt;String&gt; taskEntries) { valueA = new String[taskEntries.size()][columnName.length]; int size = taskEntries.size(); for (int i = 0; i &lt; size; i++) { String entry = taskEntries.get(i); String[] splitValues = entry.split(","); for (int j = 0; j &lt; splitValues.length; j++) { String v = splitValues[j]; v = v.replaceAll("\"", ""); // mem contains "," so added mem usage at the end if (j &gt;= 5) { valueA[i][4] = valueA[i][4] + v; } else { valueA[i][j] = v; } } } } @Override public int getRowCount() { return valueA.length; } @Override public String getColumnName(int column) { return columnName[column]; } @Override public int getColumnCount() { return columnName.length; } @Override public Object getValueAt(int rowIndex, int columnIndex) { return valueA[rowIndex][columnIndex]; } } public static void main(String[] args) { ProcessListTable gpl = new ProcessListTable(); gpl.GetProcessListData(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload