diff options
author | David Dykstal | 2006-10-02 18:45:39 +0000 |
---|---|---|
committer | David Dykstal | 2006-10-02 18:45:39 +0000 |
commit | e8d6b5d887c8f5839c23ad94074bcfb251d00350 (patch) | |
tree | bd95587e4f8e768c885c5b7fd4855b20f7bb9084 | |
parent | 602fe77bf7ff5104d3b61ce8150df26c515be2bd (diff) | |
download | org.eclipse.tm-e8d6b5d887c8f5839c23ad94074bcfb251d00350.tar.gz org.eclipse.tm-e8d6b5d887c8f5839c23ad94074bcfb251d00350.tar.xz org.eclipse.tm-e8d6b5d887c8f5839c23ad94074bcfb251d00350.zip |
Bug 158295 - initial integration
2 files changed, 130 insertions, 0 deletions
diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/processes/handlers/ProcessHandlerManager.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/processes/handlers/ProcessHandlerManager.java index 9ef4c36b0..2075d67e8 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/processes/handlers/ProcessHandlerManager.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/processes/handlers/ProcessHandlerManager.java @@ -42,6 +42,7 @@ public class ProcessHandlerManager if (osName.startsWith("linux")) return new UniversalLinuxProcessHandler(); else if (osName.startsWith("aix")) return new UniversalAIXProcessHandler(); else if (osName.startsWith("z/os")) return new UniversalZOSProcessHandler(); + else if (osName.startsWith("mac os x")) return new UniversalMacOSXProcessHandler(); else return null; } }
\ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/processes/handlers/UniversalMacOSXProcessHandler.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/processes/handlers/UniversalMacOSXProcessHandler.java new file mode 100644 index 000000000..3ae9b909d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/processes/handlers/UniversalMacOSXProcessHandler.java @@ -0,0 +1,129 @@ +/******************************************************************************** + * Copyright (c) 2005, 2006 IBM Corporation. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.clientserver.processes.handlers; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.eclipse.rse.services.clientserver.processes.HostProcessFilterImpl; +import org.eclipse.rse.services.clientserver.processes.IHostProcess; +import org.eclipse.rse.services.clientserver.processes.IHostProcessFilter; +import org.eclipse.rse.services.clientserver.processes.ISystemProcessRemoteConstants; + +public class UniversalMacOSXProcessHandler implements ProcessHandler { + private static final Map stateMap = new HashMap(); + + static { + String[] strings = ISystemProcessRemoteConstants.ALL_STATES_STR; + stateMap.put("I", strings[ISystemProcessRemoteConstants.STATE_IDLE_INDEX]); + stateMap.put("R", strings[ISystemProcessRemoteConstants.STATE_RUNNING_INDEX]); + stateMap.put("S", strings[ISystemProcessRemoteConstants.STATE_SLEEPING_INDEX]); + stateMap.put("T", strings[ISystemProcessRemoteConstants.STATE_NONEXISTENT_INDEX]); + stateMap.put("U", strings[ISystemProcessRemoteConstants.STATE_WAITING_INDEX]); + stateMap.put("Z", strings[ISystemProcessRemoteConstants.STATE_ZOMBIE_INDEX]); + } + + /** + * Creates a new ProcessHandler for Mac OS X platforms. + */ + public UniversalMacOSXProcessHandler() { + } + + /* (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.processes.handlers.ProcessHandler#lookupProcesses + */ + public SortedSet lookupProcesses(IHostProcessFilter rpfs) throws Exception { + SortedSet results = new TreeSet(new ProcessComparator()); + + // create the remote command with the Mac OS X specific attributes + String cmdLine = "/bin/ps -A -o 'pid ucomm state ppid uid user gid vsz rss'"; + // run the command and get output + Process ps = Runtime.getRuntime().exec(cmdLine); + InputStreamReader isr = new InputStreamReader(ps.getInputStream()); + BufferedReader reader = new BufferedReader(isr); + String nextLine = reader.readLine(); // Header line + nextLine = reader.readLine(); + while (nextLine != null) { + // Input line looks like "pid ucomm state ppid uid user gid vsz rss" + String[] words = nextLine.split("\\s+"); + UniversalServerProcessImpl usp = new UniversalServerProcessImpl(); + usp.setPid(words[0]); + usp.setName(words[1]); + usp.setState(convertToStateCode(words[2])); + usp.setPPid(words[3]); + usp.setUid(words[4]); + usp.setUsername(words[5]); + usp.setGid(words[6]); + usp.setVmSizeInKB(words[7]); + usp.setVmRSSInKB(words[8]); + usp.setTgid(""); + usp.setTracerPid(""); + if (rpfs.allows(usp.getAllProperties())) { + results.add(usp); + } + nextLine = reader.readLine(); + } + reader.close(); + isr.close(); + if (results.size() == 0) return null; + return results; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.processes.ProcessHandler#kill + */ + public IHostProcess kill(IHostProcess process, String type) throws Exception { + if (type.equals(ISystemProcessRemoteConstants.PROCESS_SIGNAL_TYPE_DEFAULT)) { + type = ""; + } else { + type = "-" + type; + } + + // formulate command to send kill signal + String cmdLine = "kill " + type + " " + process.getPid(); + Runtime.getRuntime().exec(cmdLine); + + // after the kill command is executed, the process might have changed + // attributes, or might be gone, so requery + HostProcessFilterImpl rpfs = new HostProcessFilterImpl(); + rpfs.setPid("" + process.getPid()); + SortedSet results = lookupProcesses(rpfs); + if (results == null || results.size() == 0) { + return null; + } else { + return (IHostProcess) results.first(); + } + } + + /** + * Return the unique state code assocated with the state given by + * the ps listing on Mac OS X. + */ + protected String convertToStateCode(String state) { + String key = state.substring(0, 0); + String stateCode = (String) stateMap.get(key); + if (stateCode == null) { + stateCode = ""; + } + return stateCode; + } + +}
\ No newline at end of file |