xlang v4.0 Release
程序设计语言基础库文档
载入中...
搜索中...
未找到
Public 成员函数 | 静态 Public 成员函数 | 包函数 | 静态包函数 | 包属性
OSProcess类 参考

Public 成员函数

静态 Public 成员函数

包函数

静态包函数

包属性

详细描述

在文件 Runtime.xcs171 行定义.

构造及析构函数说明

◆ OSProcess() [1/3]

OSProcess ( )

在文件 Runtime.xcs172 行定义.

172 {
173 }

◆ OSProcess() [2/3]

OSProcess ( int  Id)

在文件 Runtime.xcs174 行定义.

174 {
175 processId = Id;
176 }

◆ OSProcess() [3/3]

OSProcess ( byte []  data) throws IndexOutOfBoundsException , ArrayStoreException, NullPointerException
package

在文件 Runtime.xcs177 行定义.

177 {
178 for (int i = 0; i < 4; i ++) {
179 processId = (processId << 8) | data[8 + 3 - i];
180 }
181
182 byte[] paths = new byte[Win32Api.Kernel32.MAX_PATH];
183
184 _system_.arrayCopy(data, _system_.getOSBit() == 32 ? 36 : 44, paths, 0, Win32Api.Kernel32.MAX_PATH);
185 int len = Win32Api.Kernel32.lstrlenA(paths);
186 name = new String(paths, 0, len);
187 }
系统和IO相关
static final void arrayCopy(Object, long, Object, long, long)
static final int getOSBit()
字符串类

引用了 _system_.arrayCopy() , 以及 _system_.getOSBit().

成员函数说明

◆ closeHandle()

void closeHandle ( long  handle)

在文件 Runtime.xcs244 行定义.

244 {
245 Win32Api.Kernel32.CloseHandle(handle);
246 }

◆ getId()

int getId ( )

在文件 Runtime.xcs193 行定义.

193 {
194 return processId;
195 }

◆ getName()

String getName ( )

在文件 Runtime.xcs197 行定义.

197 {
198 return name;
199 }

◆ getPath()

String getPath ( )

在文件 Runtime.xcs201 行定义.

201 {
202 //PROCESS_QUERY_INFORMATION
203 if (exepath == nilptr) {
204
205 if (rtlp.rtl_osid == 0) {
206 if (false == Win32Api.Psapi32.load()) {
207 return nilptr;
208 }
209
210 long handle = open();
211
212 if (handle > 0) {
213 byte [] path = new byte[Win32Api.Kernel32.MAX_PATH];
214 int [] pl = new int[1];
215 long [] hm = new long[1];
216
217 pl[0] = Win32Api.Kernel32.MAX_PATH;
218 int up = 0;
219
220 if (Win32Api.Psapi32.EnumProcessModules(handle, hm, 8, up)) {
221 int len = Win32Api.Psapi32.GetModuleFileNameExA(handle, hm[0], path, Win32Api.Kernel32.MAX_PATH);
222
223 if (len > 0) {
224 try {
225 exepath = new String(path, 0, len);
226 } catch(Exception e) {
227
228 }
229 }
230 }
231
232 closeHandle(handle);
233 }
234 }
235 }
236
237 return exepath;
238 }
异常类
void closeHandle(long handle)
Definition Runtime.xcs:244

◆ getProcessListUnix()

static List<OSProcess> getProcessListUnix ( )
staticpackage

在文件 Runtime.xcs283 行定义.

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

引用了 List<_V>.add(), String.appendPath(), FileInputStream.close(), File.close(), File.find(), File.getName(), File.getPath(), String.isDigit(), File.open(), String.parseInt() , 以及 FileInputStream.read().

◆ getProcessListWin32()

static List<OSProcess> getProcessListWin32 ( )
staticpackage

在文件 Runtime.xcs364 行定义.

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

引用了 List<_V>.add().

◆ kill()

bool kill ( int  code)

在文件 Runtime.xcs251 行定义.

251 {
252 bool r = false;
253
254 if (rtlp.rtl_osid == 0) {
255
256 long h = open();
257
258 if (h > 0) {
259 r = Win32Api.Kernel32.TerminateProcess(h, code);
260 Win32Api.Kernel32.CloseHandle(h);
261 }
262 } else {
263 r = 0 == UnixlikeApi.kill(processId, 15);
264 }
265
266 return r;
267 }

◆ listProcesses()

static List<OSProcess> listProcesses ( )
static

在文件 Runtime.xcs270 行定义.

270 {
271 int osid = _system_.getPlatformId();
272
273 if (osid == 0) {
274 return getProcessListWin32();
275 } else if (osid == 1 || osid == 2) {
276 return getProcessListUnix();
277 }
278
279 return nilptr;
280 }
static final int getPlatformId()
static List<OSProcess> getProcessListUnix()
Definition Runtime.xcs:283
static List<OSProcess> getProcessListWin32()
Definition Runtime.xcs:364

引用了 _system_.getPlatformId().

◆ open() [1/2]

long open ( )

在文件 Runtime.xcs240 行定义.

240 {
241 return Win32Api.Kernel32.OpenProcess(0x001fffff, false, processId);
242 }

◆ open() [2/2]

long open ( int  flag,
bool  bi 
)

在文件 Runtime.xcs247 行定义.

247 {
248 return Win32Api.Kernel32.OpenProcess(flag, bi, processId);
249 }

结构体成员变量说明

◆ exepath

String exepath
package

在文件 Runtime.xcs191 行定义.

◆ name

String name
package

在文件 Runtime.xcs190 行定义.

◆ processId

int processId
package

在文件 Runtime.xcs189 行定义.