~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.core.aix/src/org/eclipse/cdt/internal/core/aix/ProcessList.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
7
 
 *
8
 
 * Contributors:
9
 
 *     QNX Software Systems - Initial API and implementation
10
 
 *******************************************************************************/
11
 
package org.eclipse.cdt.internal.core.aix;
12
 
 
13
 
import java.io.File;
14
 
import java.io.FileReader;
15
 
import java.io.FilenameFilter;
16
 
import java.io.IOException;
17
 
 
18
 
import org.eclipse.cdt.core.IProcessInfo;
19
 
import org.eclipse.cdt.core.IProcessList;
20
 
 
21
 
/**
22
 
 * Insert the type's description here.
23
 
 * @see IProcessList
24
 
 */
25
 
public class ProcessList implements IProcessList {
26
 
 
27
 
        ProcessInfo[] empty = new ProcessInfo[0];
28
 
        
29
 
        public ProcessList() {
30
 
        }
31
 
        
32
 
        /**
33
 
         * Insert the method's description here.
34
 
         * @see IProcessList#getProcessList
35
 
         */
36
 
        public IProcessInfo [] getProcessList()  {
37
 
                File proc = new File("/proc"); //$NON-NLS-1$
38
 
                File[] pidFiles = null;
39
 
                
40
 
                // We are only interrested in the pid so filter the rest out.
41
 
                try {
42
 
                        FilenameFilter filter = new FilenameFilter() {
43
 
                                public boolean accept(File dir, String name) {
44
 
                                        boolean isPID = false;
45
 
                                        try {
46
 
                                                Integer.parseInt(name);
47
 
                                                isPID = true;
48
 
                                        } catch (NumberFormatException e) {
49
 
                                        }
50
 
                                        return isPID;
51
 
                                }
52
 
                        };
53
 
                        pidFiles = proc.listFiles(filter);
54
 
                } catch (SecurityException e) {
55
 
                }
56
 
                
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();
63
 
                                try {
64
 
                                        FileReader reader = new FileReader(cmdLine);
65
 
                                        int c;
66
 
                                        while ((c = reader.read()) > 0) {
67
 
                                                line.append((char)c);
68
 
                                        }
69
 
                                } catch (IOException e) {
70
 
                                }
71
 
                                String name = line.toString();
72
 
                                if (name.length() == 0) {
73
 
                                        name = "Unknown"; //$NON-NLS-1$
74
 
                                }
75
 
                                processInfo[i] = new ProcessInfo(pidFiles[i].getName(), name);
76
 
                        }
77
 
                } else {
78
 
                        pidFiles = new File[0];
79
 
                }
80
 
                return processInfo;             
81
 
        }
82
 
}