6 public static int rtl_osid = _system_.getPlatformId();
10 static bool loaded =
false;
30 public static bool load() {
31 if (loaded ==
false) {
32 if (rtlp.rtl_osid == 1) {
33 loaded = load_linux();
35 if (loaded ==
false) {
52 Pointer cdecl readlink (
String __path,
53 ObjectPtr __buf, Pointer __len);
54 int cdecl kill(
int pid,
int sig);
61 public static bool loaded =
false;
63 public static bool load() {
64 if (loaded ==
false) {
66 loadLibrary(
"psapi.dll");
79 GetProcessImageFileNameA(
103 public static bool loaded =
false;
106 if (loaded ==
false) {
108 loadLibrary(
"kernel32.dll");
118 public static const int MAX_PATH = 260,
119 TH32CS_SNAPHEAPLIST = 1,
120 TH32CS_SNAPPROCESS = 2,
121 TH32CS_SNAPTHREAD = 4,
122 TH32CS_SNAPMODULE = 8,
123 TH32CS_SNAPALL = TH32CS_SNAPHEAPLIST | TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD | TH32CS_SNAPMODULE;
126 Pointer stdcall CreateToolhelp32Snapshot(
171 public class OSProcess{
178 for (
int i = 0; i < 4; i ++) {
179 processId = (processId << 8) | data[8 + 3 - i];
182 byte[] paths =
new byte[Win32Api.Kernel32.MAX_PATH];
185 int len = Win32Api.Kernel32.lstrlenA(paths);
186 name =
new String(paths, 0, len);
203 if (exepath == nilptr) {
205 if (rtlp.rtl_osid == 0) {
206 if (
false == Win32Api.Psapi32.load()) {
210 long handle = open();
213 byte [] path =
new byte[Win32Api.Kernel32.MAX_PATH];
214 int [] pl =
new int[1];
215 long [] hm =
new long[1];
217 pl[0] = Win32Api.Kernel32.MAX_PATH;
220 if (Win32Api.Psapi32.EnumProcessModules(handle, hm, 8, up)) {
221 int len = Win32Api.Psapi32.GetModuleFileNameExA(handle, hm[0], path, Win32Api.Kernel32.MAX_PATH);
225 exepath =
new String(path, 0, len);
241 return Win32Api.Kernel32.OpenProcess(0x001fffff,
false, processId);
245 Win32Api.Kernel32.CloseHandle(handle);
247 public long open(
int flag,
bool bi) {
248 return Win32Api.Kernel32.OpenProcess(flag, bi, processId);
254 if (rtlp.rtl_osid == 0) {
259 r = Win32Api.Kernel32.TerminateProcess(h, code);
260 Win32Api.Kernel32.CloseHandle(h);
263 r = 0 == UnixlikeApi.kill(processId, 15);
274 return getProcessListWin32();
275 }
else if (osid == 1 || osid == 2) {
276 return getProcessListUnix();
286 if (
false == UnixlikeApi.load()) {
294 long hfind = file.
open();
300 while (file.
find(hfind, pf)) {
303 if (pname != nilptr && pname.
isDigit()) {
304 OSProcess process =
new OSProcess();
307 if (fppath != nilptr) {
315 byte []status =
new byte[1024];
318 while ((rd = fis.
read(status, 0, 1024)) > 0) {
319 txtstatus = txtstatus +
new String(status, 0, rd);
324 int pos = txtstatus.indexOf(
"Name:");
327 int le = txtstatus.indexOf(
"\n", pos);
330 le = txtstatus.length();
333 process.name = txtstatus.substring(pos + 5, le).trim(
true);
341 byte [] fullpath =
new byte[4096];
342 long length = UnixlikeApi.readlink(expath, fullpath, (
long)4096);
345 process.exepath =
new String (fullpath, 0, (
int)length);
348 process.processId = pname.
parseInt();
367 if (
false == Win32Api.Kernel32.load()) {
371 byte[]
struct = new byte[356];
376 long snopt = Win32Api.Kernel32.CreateToolhelp32Snapshot(
377 Win32Api.Kernel32.TH32CS_SNAPALL,
382 bool succ = Win32Api.Kernel32.Process32First(snopt, struct);
385 plist.
add(
new OSProcess(struct));
386 succ = Win32Api.Kernel32.Process32Next(snopt, struct);
389 Win32Api.Kernel32.CloseHandle(snopt);
static final int getPlatformId()
static final void output(String)
static final void arrayCopy(Object, long, Object, long, long)
static final int getOSBit()
final String getMessage()
static final void loadLibrary(String)
void closeHandle(long handle)
static List<OSProcess> getProcessListUnix()
static List<OSProcess> getProcessListWin32()
static List<OSProcess> listProcesses()
long open(int flag, bool bi)
bool stdcall CloseHandle( Pointer hObject )
Pointer stdcall OpenProcess( int dwDesiredAccess, bool bInheritHandle, int dwProcessId)
int stdcall lstrlenA( ObjectPtr lpString )
bool stdcall QueryFullProcessImageNameA( ObjectPtr hProcess, int dwFlags, ObjectPtr lpExeName, ObjectPtr lpdwSize )
bool stdcall TerminateProcess( Pointer hProcess, int uExitCode )
bool stdcall Process32Next( Pointer hSnapshot, ObjectPtr lppe )
bool stdcall Process32First( Pointer hSnapshot, ObjectPtr lppe )
bool stdcall EnumProcessModules( Pointer hProcess, ObjectPtr lphModule, int cb, ObjectPtr lpcbNeeded )
int stdcall GetModuleFileNameExA( Pointer hProcess, Pointer hModule, ObjectPtr lpFilename, int nSize )
String appendPath(String)