klinux书籍的配套光盘。可以学习学习。

源代码在线查看: 列表5.19.txt

软件大小: 62 K
上传用户: villyc
关键词: klinux 书籍 光盘
下载地址: 免注册下载 普通下载 VIP

相关代码

				【列表5.19】枚举一个进程的所有文件。
				      type
				         // Process file enumeration callback.
				        TProcFileEnumCallback = procedure (pid: __pid_t;
				           fd: Integer) of object;
				     {
				        ProcEnumFiles - Enumerate the files used by the process.
				        If the calling process does not have permissions to
				        access the fd directory for this process, no FDs will
				        be enumerated.
				    }
				    procedure ProcEnumFiles (pid: __pid_t; cb: TProcFileEnumCallback);
				    var
				       sr : TSearchRec;
				       findRslt : Integer;
				       sFilename : String;
				       fd : Integer;
				   begin
				      sFilename := Format ('/proc/%d/fd/*,, [pid]);
				      findRslt := FindFirst (sFilename, faAnyFile, sr);
				      try
				         while findRslt = 0 do
				        begin
				           try
				              fd := StrToInt (sr. Name);
				           except
				              fd := -1;
				           end;
				           if fd  -1 then
				             cb (pid, fd);
				          findRslt := FindNext (sr);
				       end;
				    finally
				       FindClose (sr);
				    end;
				end;
				// ProcGetFD - return the contents of the link for file fd.
				function  ProcGetFD (pid: __pid_t; fd: Integer): String;
				begin
				   Result := ProcReadLink (pid, Format ('fd/%d,[fd]));
				end;                                          
							

相关资源