Windows 2000 : (Process) (Thread). , - .
Windows 2000 :
- , . .
- , EXE- DLL . , . 4- , 2 , . , , MMU (Meneger Memory Unit).
. 13 -
. | VCL | ||||
TrackBar | Win32 | BELOW_NORMAL NORMAL | LOWEST NORMAL | ||
ComboBox | Standard | NORMAL ABOVE_NORMAL | NORMAL ABOVE_NORMAL | ||
RadioButton | Standard | BELOW_NORMAL NORMAL | LOWEST NORMAL | ||
SpinEdit | Samples | ABOVE_NORMAL HIGH | LOWEST BELOW_NORMAL | ||
TrackBar | Win32 | NORMAL ABOVE_NORMAL | BELOW_NORMAL ABOVE_NORMAL | ||
ComboBox | Standard | ABOVE_NORMAL HIGH | BELOW_NORMAL NORMAL | ||
SpinEdit | Samples | BELOW_NORMAL NORMAL | ABOVE_NORMAL HIGHEST |
. 14 -
ID | ID | - | |||||
BELOW_ NORMAL | |||||||
NORMAL | |||||||
. - , . , , . , , . (, ) .
Win32 API.
CreateProcess, . 15. "", , , DLL ( ). - , . "" . , "" , . , CreateProcess TRUE. - :
|
|
- - , ;
- , ;
- - ;
- - , ;
- - , , , - ;
- , , . - .
:
- , . ;
- , , .
. 15 - CreateProcess
lpApplicationName | |
lpCommandLine | |
lpProcessAttributes | ( ) |
lpThreadAttributes | |
bInheritHandles | , |
dwCreationFlags | , ( , ) |
lpEnvironment | |
lpCurrentDirectory | |
lpStartupInfo | , |
lpProcessInformation | , : Handle . |
. 16 CreateThread
lpThreadAttributes | |
dwStackSize | |
lpStartAddress | |
lpParameter | , |
dwCreationFlags | , ( ) |
lpThreadId |
(, ) . , - . .
|
|
() , , , .. , , . .
, CreateProcess . , CreateThread, . 16.
CreateThread :
- . , , .
- . , . , . ;
- ;
- .
, CreateThread Handle , NULL.
- :
- ;
- ;
- - ;
- - ;
- - , ;
- , , ;
- , , ;
- - .
. Windows 2000 , .. , .
20 "" , . . (context switching). Windows , .
, , :
- ;
- ;
- ;
- .
, , . Windows 2000 32 , (
. 17)- , , , , . - 99% .
. , Win32 SetPriorityClass.
, Windows 2000 7 (. 18): , , , , , .
|
|
. , Win32 SetThreadPriority.
() , . . 19.
. 17
Win32 | ||
IDLE_ PRIORITY_CLASS | 0x0040 | , . , , , |
BELOW_NORMAL_ PRIORITY_CLASS | 0x4000 | , normal idle. |
NORMAL_ PRIORITY_CLASS | 0x0020 | . |
ABOVE_NORMAL_ PRIORITY_CLASS | 0x8000 | , normal high. |
HIGH_PRIORITY_ CLASS | 0x0080 | , . , , Task Manager, . |
REALTIME_PRIORITY_ CLASS | 0x0100 | , . . |
. 18
Win32 | ||
THREAD_PRIORITY_ IDLE | -15* | 16 real-time 1 . |
THREAD_PRIORITY_ LOWEST | -2 | . |
THREAD_PRIORITY_ BELOW_NORMAL | -1 | . |
THREAD_PRIORITY_ NORMAL | . | |
THREAD_PRIORITY_ ABOVE_NORMAL | . | |
THREAD_PRIORITY_ HIGHEST | . | |
THREAD_PRIORITY_TIME_CRITICAL | 15* | 31 real-time 15 . |
. 19
- THREAD_PRIORITY | - PRIORITY_CLASS | |||||
IDLE | BELOW_ NORMAL | NORMAL | ABOVE_ NORMAL | HIGH | REALTIME | |
IDLE | ||||||
LOWEST | ||||||
BELOW_NORMAL | ||||||
NORMAL | ||||||
ABOVE_NORMAL | ||||||
HIGHEST | ||||||
TIME_CRITICAL |
, , , . Win32 API GetProcessTimes GetThreadTimes.
|
|
FileTime, 64- 100 , 1 1601 . , , SystemTime ( FileTimeToSystemTime). SystemTime , - : , , , , , .
.1. , G:\DSV\SPO\3-1\MYFAMILY\LAB1, Delphi. Windows. . File½Save Project As, ( *. pas) ( *.dpr).
, . 5.
. 5
.2. Caption Form1, BoderStyle bsDialog ( ). Panel1 (), Align alTop Caption.
, Align alTop:
- Label1 (Caption = );
- StringGrid1 (ColCount = 2, Enabled = False, FixedCols = 0, FixedRows = 0, RowCount = 4);
- Label2 (Caption = );
- TrackBar1 (Max = 4, Position = 2).
Label1 Label2 StringGrid1 () TrackBar1 ().
, , StringGrid1 OnCreate TForm1, :
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Cells[0,0]:=' ';
StringGrid1.Cells[0,1]:=' ';
StringGrid1.Cells[0,2]:=' ';
StringGrid1.Cells[0,3]:=' ';
end;
(
. 17). - REALTIME_PRIORITY_CLASS, TrackBar1 . Delphi NORMAL_PRIORITY_CLASS, .
OnChange TrackBar1, :
procedure TForm1.TrackBar1Change(Sender: TObject);
var ClassPriority: integer;
begin
case TrackBar1.Position of
0: ClassPriority:=IDLE_PRIORITY_CLASS;
// 1: ClassPriority:=BELOW_NORMAL_PRIORITY_CLASS;
1: ClassPriority:=$4000;
2: ClassPriority:=NORMAL_PRIORITY_CLASS;
// 3: ClassPriority:=ABOVE_NORMAL_PRIORITY_CLASS;
3: ClassPriority:=$8000;
4: ClassPriority:=HIGH_PRIORITY_CLASS;
end;
SetPriorityClass(GetCurrentProcess,ClassPriority);
end;
Delphi 6.0 Windows 2000: BELOW_NORMAL_PRIORITY_CLASS ABOVE_NORMAL_PRIORITY_CLASS, . Handle Win32 GetCurrentProcess SetPriorityClass, Windows SDK Delphi.
Button1 (Caption = ) OnClick :
procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;
Timer co System. Timer , . : , Interval, OnTimer. , . 1 . (1000 ).
|
|
procedure TForm1.Timer1Timer(Sender: TObject);
var STime: TSystemTime;
CrTime,ExTime,KrTime,UsTime: TFileTime;
begin
StringGrid1.Cells[1,0]:=IntToStr(GetCurrentProcessID);
StringGrid1.Cells[1,3]:=IntToStr(GetPriorityClass(GetCurrentProcess));
if GetProcessTimes(GetCurrentProcess,CrTime,ExTime,KrTime,UsTime) then begin
if FileTimeToSystemTime(CrTime,STime) then
StringGrid1.Cells[1,1]:=DateTimeToStr(SystemTimeToDateTime(STime));
if FileTimeToSystemTime(UsTime,STime) then
StringGrid1.Cells[1,2]:=TimeToStr(SystemTimeToDateTime(STime));
end;
end;
Win32 GetCurrentProcessID, GetPriorityClass. , , Win32 GetProcessTimes, TFileTime. :
- TFileTime TSystemTime FileTimeToSystemTime;
- TSystemTime TDateTime SystemTimeToDateTime;
- TDateTime DateTimeToStr TimeToStr -
TDateTime Delphi. TDateTime Double, , 30 1899 , (6.00 0.25, 12.00 0.5, 18.00 0.75).
.
.2. File/New/Other/Thread Object. , TMyThread. .
unit Unit1;
interface
uses Classes;
type
TMyThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;
implementation
procedure TMyThread.Execute;
begin
end;
end.
TThread, , - Delphi , Win32 API. Windows API , Handle. Execute , .
, , Counter, TMyThread public Counter Integer.
type
TMyThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
public
Counter: Integer;
end;
Execute, , :
procedure TMyThread.Execute;
var i,Total: integer;
begin
while not Terminated do begin
Total:=0;
for i:=1 to 10 do Inc(Total,Random(MaxInt div 10));
Inc(Counter);
end;
, Execute , . Terminated . Terminated True , - , .
, , , Unit1. , , . uses interface , , :
Uses ., Unit1;
(var) , :
Var Thread1,Thread2: TMyThread;
.
Panel2 (), Align alLeft Caption.
, Align alTop:
- Label3 (Caption = 1);
- StringGrid2 (ColCount = 2, Enabled = False, FixedCols = 0, FixedRows = 0, RowCount = 5);
- Label4 (Caption = );
- TrackBar1 (Max = 5, Position = 0).
:
- CheckBox1 (Caption = );
- Button2 (Caption = );
- Button3 (Caption = );
- Button4 (Caption = );
- Button5 (Caption = );
Label3 Label4 StringGrid2 TrackBar2).
. StringGrid2 Button1÷Button5, , OnCreate , :
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid2.Cells[0,0]:='
StringGrid2.Cells[0,1]:=' ';
StringGrid2.Cells[0,2]:=' ';
StringGrid2.Cells[0,3]:=' ';
StringGrid2.Cells[0,4]:=' ';
Button3.Enabled:=false;
Button4.Enabled:=false;
Button5.Enabled:=false;
end;
TrackBar2 (
. 17). Delphi , Win32 . 20.
- THREAD_PRIORITY_TIME_CRITICAL, TrackBar2 .
. 20 Delphi Win32
Delphi | Win32 | |
tpIdle | THREAD_PRIORITY_IDLE | -15* |
tpLowest | THREAD_PRIORITY_LOWEST | -2 |
tpLower | THREAD_PRIORITY_BELOW_NORMAL | -1 |
tpNormal | THREAD_PRIORITY_NORMAL | |
tpHigher | THREAD_PRIORITY_ABOVE_NORMAL | |
tpHighest | THREAD_PRIORITY_HIGHEST | |
tpTimeCritical | THREAD_PRIORITY_TIME_CRITICAL | 15* |
, , - . public TForm1 SetThrPrior:
type
TForm1 = class(TForm)
private
{ Private declarations }
public
procedure SetThrPrior(Thread: TMyThread; Pos: integer);
{ Public declarations }
end;
implementation :
procedure TForm1.SetThrPrior(Thread: TMyThread; Pos: integer);
var Priority: TThreadPriority;
begin
if Thread <> nil then begin
case Pos of
0: Priority:=tpIdle;
1: Priority:=tpLowest;
2: Priority:=tpLower;
3: Priority:=tpNormal;
4: Priority:=tpHigher;
5: Priority:=tpHighest;
end; {case}
Thread.Priority:=Priority;
end;
end;
Priority, TThreadPriority. OnChange TrackBar2:
procedure TForm1.TrackBar2Change(Sender: TObject);
begin
SetThreadPriority(Thread1,TrackBar2.Position);
end;
(. 5). OnClick :
procedure TForm1.Button2Click(Sender: TObject);
begin
Thread1:=TMyThread.Create(CheckBox1.Checked);
SetThreadPriority(Thread1,TrackBar2.Position);
if CheckBox1.Checked then begin
Button3.Enabled:=True;
Button4.Enabled:=False;
Button5.Enabled:=True;
end else begin
Button3.Enabled:=False;
Button4.Enabled:=True;
Button5.Enabled:=True;
end;
Button2.Enabled:=False;
end;
Create, ( ). .
Create CreateSuspended, , . CreateSuspended True, , .. , Execute , Resume. . CheckBox, ( ) hecked, .
, , Onlick Resume:
procedure TForm1.Button3Click(Sender: TObject);
begin
SetThreadPriority(Thread1,TrackBar2.Position);
Thread1.Resume;
Button3.Enabled:=False;
Button4.Enabled:=True;
end;
() Suspend . , , , Execute :
procedure TForm1.Button4Click(Sender: TObject);
begin
Thread1.Suspend;
Button3.Enabled:=True;
Button4.Enabled:=False;
end;
Terminate ( StringGrid2 ):
procedure TForm1.Button5Click(Sender: TObject);
var i: integer;
begin
Thread1.Terminate;
Button2.Enabled:=True;
Button3.Enabled:=False;
Button4.Enabled:=False;
Button5.Enabled:=False;
for i:=0 to StringGrid2.RowCount-1 do
StringGrid2.Cells[1,i]:='';
end;
, , .
OnTimer :
procedure TForm1.Timer1Timer(Sender: TObject);
var STime: TSystemTime;
CrTime,ExTime,KrTime,UsTime: TFileTime;
begin
if Thread1 <> nil then
if not Thread1.Terminated then begin
StringGrid2.Cells[1,0]:=IntToStr(Thread1.ThreadID);
StringGrid2.Cells[1,3]:=IntToStr(Thread1.Counter);
StringGrid2.Cells[1,4]:=IntToStr(GetThreadPriority(Thread1.Handle));
if GetThreadTimes(Thread1.Handle,CrTime,ExTime,KrTime,UsTime)
then begin
if FileTimeToSystemTime(CrTime,STime) then
StringGrid2.Cells[1,1]:=DateTimeToStr(SystemTimeToDateTime(STime));
if FileTimeToSystemTime(UsTime,STime) then
StringGrid2.Cells[1,2]:=TimeToStr(SystemTimeToDateTime(STime));
end;
Thread1.Counter:=0;
end;
end;
(), , ThreadID . Win32 GetThreadPriority. , , Win32 GetThreadTimes, TFileTime. .2 .
.4. , .3, . Panel2, , , Edit|Copy. Edit|Paste. Align Panel3 alRight. , Panel2 Panel3 .
, ( .3 ) :
- Form1 ( OnCreate);
- Timer1 (OnTimer);
- Button6 ÷ Button9 (OnClick);
- TrackBar3 (OnChange).
.
.5. Windows Ctrl+Alt+Delete .
.6. , . OpenDilog Dilogs, , . , .
, .
WinExec Windows API. WinExec :
UINT WinExec(
LPCSTR lpCmdLine, //
UINT uCmdShow //
);
, :
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
WinExec(PChar(OpenDialog1.FileName),SW_SHOW);
end;
, .
Windows API CreateProcess, .
1. Windows 2000?
2. ?
3. ?
4. ?
5. ?
6. Win32 API .
7. Delphi .
8. ?
9. Windows 2000?
10. Windows 2000 ?
11. Windows 2000?
12. Windows 2000 ?
13. ?
14. ?
4