mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Bug 158295 - initial integration
This commit is contained in:
parent
602fe77bf7
commit
e8d6b5d887
2 changed files with 130 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue