xlang v5.1 Release
程序设计语言基础库文档
载入中...
搜索中...
未找到
OSProcess类 参考
OSProcess 的协作图:
Collaboration graph

Public 成员函数

静态 Public 成员函数

包函数

静态包函数

包属性

详细描述

在文件 Runtime.xcs186 行定义.

构造及析构函数说明

◆ OSProcess() [1/3]

OSProcess ( )

在文件 Runtime.xcs187 行定义.

187 {
188 }

◆ OSProcess() [2/3]

OSProcess ( int  Id)

在文件 Runtime.xcs189 行定义.

189 {
190 processId = Id;
191 }

◆ OSProcess() [3/3]

OSProcess ( PROCESSENTRY32  entry) throws IndexOutOfBoundsException , ArrayStoreException, NullPointerException
package

在文件 Runtime.xcs192 行定义.

192 {
193 processId = entry.th32ProcessID;
194 int len = Win32Api.Kernel32.lstrlenA(entry.szExeFile);
195 if (len > 0){
196 name = new String(entry.szExeFile, 0, len);
197 }
198 }
Definition String.x:5

成员函数说明

◆ closeHandle()

void closeHandle ( long  handle)

在文件 Runtime.xcs255 行定义.

255 {
256 Win32Api.Kernel32.CloseHandle(handle);
257 }

◆ getId()

int getId ( )

在文件 Runtime.xcs204 行定义.

204 {
205 return processId;
206 }

◆ getName()

String getName ( )

在文件 Runtime.xcs208 行定义.

208 {
209 return name;
210 }

◆ getPath()

String getPath ( )

在文件 Runtime.xcs212 行定义.

212 {
213 //PROCESS_QUERY_INFORMATION
214 if (exepath == nilptr) {
215
216 if (rtlp.rtl_osid == 0) {
217 if (false == Win32Api.Psapi32.load()) {
218 return nilptr;
219 }
220
221 long handle = open();
222
223 if (handle > 0) {
224 byte [] path = new byte[Win32Api.Kernel32.MAX_PATH];
225 int [] pl = new int[1];
226 long [] hm = new long[1];
227
228 pl[0] = Win32Api.Kernel32.MAX_PATH;
229 int up = 0;
230
231 if (Win32Api.Psapi32.EnumProcessModules(handle, hm, 8, up)) {
232 int len = Win32Api.Psapi32.GetModuleFileNameExA(handle, hm[0], path, Win32Api.Kernel32.MAX_PATH);
233
234 if (len > 0) {
235 try {
236 exepath = new String(path, 0, len);
237 } catch(Exception e) {
238
239 }
240 }
241 }
242
243 closeHandle(handle);
244 }
245 }
246 }
247
248 return exepath;
249 }
void closeHandle(long handle)
Definition Runtime.xcs:255

◆ getProcessListUnix()

static List<OSProcess> getProcessListUnix ( )
staticpackage

在文件 Runtime.xcs294 行定义.

294 {
295 List<OSProcess> plist = nilptr;
296
297 if (false == UnixlikeApi.load()) {
298 return nilptr;
299 }
300
301 plist = new List<OSProcess>();
302
303 try {
304 File file = new File ("/proc");
305 long hfind = file.open();
306
307 if (hfind != 0) {
308 File pf = new File();
309
310 while (file.find(hfind, pf)) {
311 String pname = pf.getName();
312
313 if (pname != nilptr && pname.isDigit()) {
314 OSProcess process = new OSProcess();
315 String fppath = pf.getPath();
316
317 if (fppath != nilptr) {
318 String namepath = fppath.appendPath("status");
319
320 long fis = _system_.open(namepath, _system_.READ);
321
322 if (fis > 0) {
323 String txtstatus = "";
324 byte []status = new byte[1024];
325 int rd = 0;
326
327 while ((rd = _system_.read(fis, status, 0, 1024)) > 0) {
328 txtstatus = txtstatus + new String(status, 0, rd);
329 }
330
331 _system_.close(fis);
332 int pos = txtstatus.indexOf("Name:");
333
334 if (pos != -1) {
335 int le = txtstatus.indexOf("\n", pos);
336 if (le == -1) {
337 le = txtstatus.length();
338 }
339 process.name = txtstatus.substring(pos + 5, le).trim(true);
340 }
341 }
342
343 String expath = fppath.appendPath("exe");
344 byte [] fullpath = new byte[4096];
345 long length = UnixlikeApi.readlink(expath, fullpath, (long)4096);
346
347 if (length != -1) {
348 process.exepath = new String (fullpath, 0, (int)length);
349 }
350
351 process.processId = pname.parseInt();
352 plist.add(process);
353 }
354 }
355 }
356
357 file.close(hfind);
358 }
359 } catch(Exception e) {
360
361 }
362
363 return plist;
364 }
static final long read(long, byte[], long, long)
static const int READ
Definition _system_.x:232
static final long open(String, int)
static final bool close(long)
Definition File.x:4
String getPath()
String getName()
long open()
bool find(long, File)
void close(long)
int length()
String substring(int, int)
bool isDigit()
String appendPath(String)
String trim(bool)
int indexOf(String, int)
int parseInt()

引用了 String.appendPath(), _system_.close(), File.close(), File.find(), File.getName(), File.getPath(), String.indexOf(), String.isDigit(), String.length(), File.open(), _system_.open(), String.parseInt(), _system_.READ, _system_.read(), String.substring() , 以及 String.trim().

函数调用图:

◆ getProcessListWin32()

static List<OSProcess> getProcessListWin32 ( )
staticpackage

在文件 Runtime.xcs367 行定义.

367 {
368 List<OSProcess> plist = nilptr;
369
370 if (false == Win32Api.Kernel32.load()) {
371 return nilptr;
372 }
373
374 PROCESSENTRY32 struct = new PROCESSENTRY32();
375 plist = new List<OSProcess>();
376
377 long snopt = Win32Api.Kernel32.CreateToolhelp32Snapshot(
378 Win32Api.Kernel32.TH32CS_SNAPALL,
379 0);
380
381 try {
382 if (snopt > 0) {
383 bool succ = Win32Api.Kernel32.Process32First(snopt, struct);
384
385 while (succ) {
386 plist.add(new OSProcess(struct));
387 succ = Win32Api.Kernel32.Process32Next(snopt, struct);
388 }
389
390 Win32Api.Kernel32.CloseHandle(snopt);
391 }
392 } catch(Exception e) {
393
394 }
395
396 return plist;
397 }

◆ kill()

bool kill ( int  code)

在文件 Runtime.xcs262 行定义.

262 {
263 bool r = false;
264
265 if (rtlp.rtl_osid == 0) {
266
267 long h = open();
268
269 if (h > 0) {
270 r = Win32Api.Kernel32.TerminateProcess(h, code);
271 Win32Api.Kernel32.CloseHandle(h);
272 }
273 } else {
274 r = 0 == UnixlikeApi.kill(processId, 15);
275 }
276
277 return r;
278 }

◆ listProcesses()

static List<OSProcess> listProcesses ( )
static

在文件 Runtime.xcs281 行定义.

281 {
282 int osid = _system_.getPlatformId();
283
284 if (osid == 0) {
285 return getProcessListWin32();
286 } else if (osid == 1 || osid == 2) {
287 return getProcessListUnix();
288 }
289
290 return nilptr;
291 }
static final int getPlatformId()
static List<OSProcess> getProcessListUnix()
Definition Runtime.xcs:294
static List<OSProcess> getProcessListWin32()
Definition Runtime.xcs:367

引用了 _system_.getPlatformId().

函数调用图:

◆ open() [1/2]

long open ( )

在文件 Runtime.xcs251 行定义.

251 {
252 return Win32Api.Kernel32.OpenProcess(0x001fffff, false, processId);
253 }

◆ open() [2/2]

long open ( int  flag,
bool  bi 
)

在文件 Runtime.xcs258 行定义.

258 {
259 return Win32Api.Kernel32.OpenProcess(flag, bi, processId);
260 }

结构体成员变量说明

◆ exepath

String exepath
package

在文件 Runtime.xcs202 行定义.

◆ name

String name
package

在文件 Runtime.xcs201 行定义.

◆ processId

int processId
package

在文件 Runtime.xcs200 行定义.