1
/*******************************************************************************
2
* Copyright (c) 2000, 2006 QNX Software Systems and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* QNX Software Systems - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.internal.core.aix;
14
import java.io.FileReader;
15
import java.io.FilenameFilter;
16
import java.io.IOException;
18
import org.eclipse.cdt.core.IProcessInfo;
19
import org.eclipse.cdt.core.IProcessList;
22
* Insert the type's description here.
25
public class ProcessList implements IProcessList {
27
ProcessInfo[] empty = new ProcessInfo[0];
29
public ProcessList() {
33
* Insert the method's description here.
34
* @see IProcessList#getProcessList
36
public IProcessInfo [] getProcessList() {
37
File proc = new File("/proc"); //$NON-NLS-1$
38
File[] pidFiles = null;
40
// We are only interrested in the pid so filter the rest out.
42
FilenameFilter filter = new FilenameFilter() {
43
public boolean accept(File dir, String name) {
44
boolean isPID = false;
46
Integer.parseInt(name);
48
} catch (NumberFormatException e) {
53
pidFiles = proc.listFiles(filter);
54
} catch (SecurityException e) {
57
ProcessInfo[] processInfo = empty;
58
if (pidFiles != null) {
59
processInfo = new ProcessInfo[pidFiles.length];
60
for (int i = 0; i < pidFiles.length; i++) {
61
File cmdLine = new File(pidFiles[i], "cmdline"); //$NON-NLS-1$
62
StringBuffer line = new StringBuffer();
64
FileReader reader = new FileReader(cmdLine);
66
while ((c = reader.read()) > 0) {
69
} catch (IOException e) {
71
String name = line.toString();
72
if (name.length() == 0) {
73
name = "Unknown"; //$NON-NLS-1$
75
processInfo[i] = new ProcessInfo(pidFiles[i].getName(), name);
78
pidFiles = new File[0];