|
Added
Link Here
|
| 1 |
/******************************************************************************** |
| 2 |
* Copyright (c) 2009 IBM Corporation. All rights reserved. |
| 3 |
* This program and the accompanying materials are made available under the terms |
| 4 |
* of the Eclipse Public License v1.0 which accompanies this distribution, and is |
| 5 |
* available at http://www.eclipse.org/legal/epl-v10.html |
| 6 |
* |
| 7 |
* Initial Contributors: |
| 8 |
* The following IBM employees contributed to the Remote System Explorer |
| 9 |
* component that contains this file: David McKnight. |
| 10 |
* |
| 11 |
* Contributors: |
| 12 |
* David McKnight (IBM) - [175293] [dstore] Processes do not work on Dstore-UNIX connection to Solaris |
| 13 |
********************************************************************************/ |
| 14 |
package org.eclipse.rse.services.clientserver.processes.handlers; |
| 15 |
|
| 16 |
import java.io.BufferedReader; |
| 17 |
import java.io.InputStreamReader; |
| 18 |
import java.util.HashMap; |
| 19 |
import java.util.SortedSet; |
| 20 |
import java.util.TreeSet; |
| 21 |
|
| 22 |
import org.eclipse.rse.services.clientserver.processes.IHostProcess; |
| 23 |
import org.eclipse.rse.services.clientserver.processes.IHostProcessFilter; |
| 24 |
|
| 25 |
/** |
| 26 |
* @since 3.1 |
| 27 |
*/ |
| 28 |
public class UniversalSolarisProcessHandler extends UniversalAIXProcessHandler { |
| 29 |
|
| 30 |
private static final String[] processAttributes = {"pid","ppid","comm","uid","user","gid","vsz","s"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ |
| 31 |
private static final String firstColumnHeader = "PID"; //$NON-NLS-1$ |
| 32 |
|
| 33 |
|
| 34 |
public IHostProcess kill(IHostProcess process, String type) |
| 35 |
throws Exception { |
| 36 |
return super.kill(process, type); |
| 37 |
} |
| 38 |
|
| 39 |
/* (non-Javadoc) |
| 40 |
* @see org.eclipse.rse.services.clientserver.processes.handlers.ProcessHandler#lookupProcesses |
| 41 |
*/ |
| 42 |
public SortedSet lookupProcesses(IHostProcessFilter rpfs) |
| 43 |
throws Exception |
| 44 |
{ |
| 45 |
SortedSet results = new TreeSet(new ProcessComparator()); |
| 46 |
|
| 47 |
// create the remote command with the UNIX specific attributes |
| 48 |
String cmdLine = "/usr/bin/ps -A -o "; //$NON-NLS-1$ |
| 49 |
for (int i = 0; i < processAttributes.length; i++) |
| 50 |
{ |
| 51 |
cmdLine = cmdLine + processAttributes[i]; |
| 52 |
if ((processAttributes.length - i > 1)) cmdLine = cmdLine + ","; //$NON-NLS-1$ |
| 53 |
} |
| 54 |
// run the command and get output |
| 55 |
Process ps = Runtime.getRuntime().exec(cmdLine); |
| 56 |
InputStreamReader isr = new InputStreamReader(ps.getInputStream()); |
| 57 |
|
| 58 |
BufferedReader reader = new BufferedReader(isr); |
| 59 |
|
| 60 |
String nextLine = reader.readLine(); |
| 61 |
if (nextLine != null && nextLine.trim().startsWith(firstColumnHeader)) nextLine = reader.readLine(); |
| 62 |
while (nextLine != null) |
| 63 |
{ |
| 64 |
String statusLine = ""; //$NON-NLS-1$ |
| 65 |
// put the details of each process into a hashmap |
| 66 |
HashMap psLineContents = getPSOutput(nextLine); |
| 67 |
if (psLineContents == null) |
| 68 |
{ |
| 69 |
nextLine = reader.readLine(); |
| 70 |
continue; |
| 71 |
} |
| 72 |
|
| 73 |
String pid = (String) psLineContents.get("pid"); //$NON-NLS-1$ |
| 74 |
statusLine = pid + "|"; //$NON-NLS-1$ |
| 75 |
|
| 76 |
// add the name to the status string |
| 77 |
String name = (String) psLineContents.get("comm"); //$NON-NLS-1$ |
| 78 |
if (name == null) name = " "; //$NON-NLS-1$ |
| 79 |
statusLine = statusLine + name + "|"; //$NON-NLS-1$ |
| 80 |
|
| 81 |
// add the status letter to the status string |
| 82 |
String state = (String) psLineContents.get("s"); //$NON-NLS-1$ |
| 83 |
if (state == null) state = " "; //$NON-NLS-1$ |
| 84 |
String stateCode = convertToStateCode(state); |
| 85 |
statusLine = statusLine + stateCode + "|"; //$NON-NLS-1$ |
| 86 |
|
| 87 |
// add the Tgid |
| 88 |
String tgid = (String) psLineContents.get("tgid"); //$NON-NLS-1$ |
| 89 |
if (tgid == null) tgid = " "; //$NON-NLS-1$ |
| 90 |
statusLine = statusLine + tgid + "|"; //$NON-NLS-1$ |
| 91 |
|
| 92 |
// add the Ppid |
| 93 |
String pPid = (String) psLineContents.get("ppid"); //$NON-NLS-1$ |
| 94 |
if (pPid == null) pPid = " "; //$NON-NLS-1$ |
| 95 |
statusLine = statusLine + pPid + "|"; //$NON-NLS-1$ |
| 96 |
|
| 97 |
// add the TracerPid |
| 98 |
String tracerpid = (String) psLineContents.get("tracerpid"); //$NON-NLS-1$ |
| 99 |
if (tracerpid == null) tracerpid = " "; //$NON-NLS-1$ |
| 100 |
statusLine = statusLine + tracerpid + "|"; //$NON-NLS-1$ |
| 101 |
|
| 102 |
String uid = (String) psLineContents.get("uid"); //$NON-NLS-1$ |
| 103 |
if (uid == null) uid = " "; //$NON-NLS-1$ |
| 104 |
statusLine = statusLine + uid + "|"; // add the uid to the status string //$NON-NLS-1$ |
| 105 |
|
| 106 |
String username = (String) psLineContents.get("user"); //$NON-NLS-1$ |
| 107 |
if (username == null) username = " "; //$NON-NLS-1$ |
| 108 |
statusLine = statusLine + username + "|"; // add the username to the status string //$NON-NLS-1$ |
| 109 |
|
| 110 |
// add the gid to the status string |
| 111 |
String gid = (String) psLineContents.get("gid"); //$NON-NLS-1$ |
| 112 |
if (gid == null) gid = " "; //$NON-NLS-1$ |
| 113 |
statusLine = statusLine + gid + "|"; //$NON-NLS-1$ |
| 114 |
|
| 115 |
// add the VmSize to the status string |
| 116 |
String vmsize = (String) psLineContents.get("vsz"); //$NON-NLS-1$ |
| 117 |
if (vmsize == null) vmsize = " "; //$NON-NLS-1$ |
| 118 |
statusLine = statusLine + vmsize +"|"; //$NON-NLS-1$ |
| 119 |
|
| 120 |
// add a dummy vmrss to the status string |
| 121 |
// vmRss is not available on ZOS |
| 122 |
String vmrss = " "; //$NON-NLS-1$ |
| 123 |
statusLine = statusLine + vmrss; |
| 124 |
|
| 125 |
if (rpfs.allows(statusLine)) |
| 126 |
{ |
| 127 |
UniversalServerProcessImpl usp = new UniversalServerProcessImpl(statusLine); |
| 128 |
results.add(usp); |
| 129 |
} |
| 130 |
nextLine = reader.readLine(); |
| 131 |
} |
| 132 |
reader.close(); |
| 133 |
isr.close(); |
| 134 |
if (results.size() == 0) return null; |
| 135 |
return results; |
| 136 |
} |
| 137 |
|
| 138 |
} |