This presentation is the property of its rightful owner.
Sponsored Links
1 / 85

Операционные системы PowerPoint PPT Presentation


  • 166 Views
  • Uploaded on
  • Presentation posted in: General

Операционные системы. Межпроцессное взаимодействие. Виды межпроцессного взаимодействия ( IPC ). Передача информации от одного процесса другому Предотвращение критических ситуаций Синхронизация процессов. Межпроцессное взаимодействие.

Download Presentation

Операционные системы

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


4457706


4457706

(IPC)


4457706


4457706

()

.


4457706

  • .

  • , , , , , .


4457706

  • , , .

  • .

  • , . , , , .


4457706

  • ,


4457706


4457706

  • (Dijkstra) , . , , .

  • - S >= 0, :

    • V(S): S 1 . S .

    • P(S): S 1, . S=0 S, , , , , . .


4457706

.


4457706

  • , , .

  • N , . - - . , .

  • - , , . , - , , .


4457706

: , f , =N, a f =0. .


4457706

  • , , , , (, , ), , . .


4457706

  • (mutex, mutual exclusion ). .

  • , : .

  • .

  • , .


4457706

, , , . () b. .


4457706

  • 1974 . (Hoare) (Brinch Hansen) .

  • .

  • , , .

  • , .

  • . .

  • , , .


4457706


4457706

Windows 2000


4457706

  • , . - . (synchronization).

  • , .

  • , , , : , . . , .


4457706

, , , .


4457706

  • Win2000 .

  • (synchronization objects) , .

  • : (signaled state) .

  • , , .

  • - , "", . , "", . , ( "").


4457706

, ( ). ( ), , .


4457706

DWORD WaitForMultipleObjects(

DWOHD dwCount,

CONST HANDLE* phObjects,

BOOL fWaitAll,

DWORD dwMilliseconds

);

DWORD WaitForSingleObject(

HANDLE hObject,

DWORD dwMilliseconds

);

WaitForSingleObject (hProcess, INFINITE);


4457706

  • Wait- - .

  • , , hObject, , - ( , .) , dwMilliseconds, , ( ) .

  • , , , hProcess.

  • WaitForMultipleObjects WaitForSingleObject c , - .

  • dwCount 1 MAXIMUM_WAIT_OBJECTS ( Windows 64). phObject .

  • WaitForMultipleObjects , . fWaitAll , . TRUE, , .


4457706


4457706

  • .

  • ( ) : -, ( ).

  • - . - : (manual-reset events) (auto-reset events). , . . .

  • - , - , , . " . , . , , .


4457706


4457706

HANDLE CreateEvent( PSECURITY_ATTRIBUTES psa,

BOOL fManualReset,

BOOL fInitialState,

PCTSTR pszName);

HANDLE OpenEvent(

DWORD fdwAccess,

BOOL fInhent,

PCTSTR pszName);


4457706

  • " CreateEvent.

  • fManualReset ( ) , (TRUE) (FALSE).

  • fInitialState (TRUE) (FALSE). , CreateEvent , .

  • :

    • DuplicateHandle;

    • OpenEvent c pszName , CreateEvent.


4457706

  • :

    BOOL SetEvent(HANDLE hEvent);

  • :

    BOOL ResetEvent(HANDLE hEvent);

  • :

    BOOL PulseEvent(HANDLE hEvent);


Pulseevent

PulseEvent

  • PulseEvent() ;

  • SetEvent() ResetEvent(). PulseEvent , , , .

  • PulseEvent . -, .


4457706

(waitable timers) , .


4457706

HANDLE CreateWaitableTimer( PSECURITY_ATTRIBUTES psa,

BOOL fManualReset,

PCTSTR pszName);

HANDLE OpenWaitableTimer(

DWORD dwDesiredAccess,

BOOL bInheritHandle,

PCTSTR pszName);

  • fManualReset : . , , , .

  • .


4457706

BOOL SetWaitableTimer(

HANDLE hTimer,

const LARGE_INTEGER *pDueTime,

LONG lPeriod,

PTIMERAPCROUTINE pfnCompletionRoutine,

PVOID pvArgToCompletionRoutine,

BOOI fResume);

BOOL CancelWaitableTimer(HANDLE hTimer);


4457706

  • , . , hTimer . (pDuim lPeriod) , , , , .

  • , ( ) 0 lPeriod CloseHandle, , SetWaitableTimer .

  • Resume . FALSE, . , , -, , TRUE , ( ), , . - WAV- .

  • CancelWaitableTimer ( ), , SetWaitableTimer. , , CancelWaitableTimer SetWaitableTimer ; SetWaitableTimer .


4457706

HANDLE CreateSemaphore(

PSECURITY_ATTRIBUTE psa,

LONG lInitialCount,

LONG lMaximumCount,

PCTRTR pszName);

HANDLE OpenSemaphore(

DWORD fdwAccess,

BOOL bInheritHandle,

PCTSTR pszName);

  • lMaximumCount .


4457706

, Wait- , Wait- 0 ( ), 1, .

BOOL ReleaseSemaphore(

HANDLE hSem,

LONG lReleaseCount,

PLONG plPreviousCount);


4457706

  • Wait- , 0 ( ), , ( , , 1).

  • , ReleaseSemaphore.

  • lReleaseCount . lReleaseCount 1.

  • *plPreviousCount.


4457706

HANDLE CreateMutex(

PSECURITY_ATTRIBUTES psa,

BOOL fInitialOwner,

PCTSTR pszName);

HANDLE OpenMutex(

DWORD fdwAccess,

BOOL fInheritHandle,

PCTSTR pszName);

  • fInitialOwner . FALSE ( ), - . 0

  • TRUE, , , , 1. 0, .


4457706

  • , Wait- , . Wait- , 0, , , .

  • Wait- , 0 ( ), . , , , 1, .

  • , . , , . , , , ReleaseMutex.

    BOOL ReleaseMutex(HANDLE hMutex);


4457706


4457706

(IPC)

  • DDE (Dynamic Data Exchange),

  • OLE,

  • atom ()

  • pipes ( ),

  • named pipes ( )

  • (mailslots)

  • RPC

  • , (memory-mapped files)

  • (Shared Memory). , .


4457706

(IPC)


4457706

  • - IPC. , . , 32- (), . .

  • (atom table). . :

    • ( )

    • ( )


4457706

  • GlobalAddAtom

  • GlobalGetAtomName

  • GlobalFindAtom

  • GlobalDeleteAtom


Wm copydata

WM_COPYDATA

:

COPYDATASTRUCT cds;

cds.cbData = (DWORD) nSize;

cds.lpData = (PVOID) pBuffer;

SendMessage (hWndTarget, WM_COPYDATA, (WPARAM) hWnd, (LPARAM) &cds);

:

PCOPYDATASTRUCT pcds = (PCOPYDATASTRUCT) lParam;

PBYTE pBuffer = (PBYTE) pcds -> lpData;


Wm copydata1

WM_COPYDATA

  • WM_COPYDATA . 32- 16- .

  • WM_COPYDATA COPYDATASTRUCT , . SendMessage WM_COPYDATA ; wParam , lParam - COPYDATASTRUCT.

  • WM_COPYDATA , COPYDATASTRUCT , .

  • , lpData, cbData. , lpData , , , . , WM_COPYDATA Windows NT , lpData. , .

  • COPYDATASTRUCT , , dwData, 32- , . , .

  • WM_COPYDATA : , . , , . , WM_COPYDATA , . , . , , lpData, .


4457706

  • .

  • .

  • .

  • .

  • .


4457706

FIFO (first input and first output - , ).

, (pipe) , , .


4457706

  • .

  • p GUI-p, . , .

  • pp / , . , . , . p -p.

  • , .


4457706

BOOL CreatePipe(

PHANDLE hReadPipe,

PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes,

DWORD nSize

);

ReadFile

WriteFile


4457706

  • pReadHandle - dword, .

  • pWriteHandle - dword, .

  • pPipeAttributes pp SECURITY_ATTRIBUTES, p p, .

  • nBufferSize - pp , ppp . pp. p NULL, pp .

  • pp bInheritable pp SECURITY_ATTRIBUTES TRUE, .


4457706

  • pp bInheritable pp SECURITY_ATTRIBUTES TRUE, .

  • CreateProcess blnheritHandles = TRUE

  • ( , )

  • DuplicateHandle


4457706

BOOL DuplicateHandle(

HANDLE hSourceProcessHandle,

HANDLE hSourceHandle,

HANDLE hTargetProcessHandle,

LPHANDLE lpTargetHandle,

DWORD dwDesiredAccess,

BOOL bInheritHandle,

DWORD dwOptions

);


4457706

  • DuplicateHandle , , , .

  • , hSourceHandle, . , DuplicateHandle, , hSourceProcessHandie. phTargetHandle HANDLE, -. , phTargetProcessHandle.

  • DuplicateHandle , -. , , dwOptions 0 . DUPLICATE_SAME_ACCESS DUPLICATE_CLOSE_SOURCE

  • DuplicateHandle: , -, , - DuplicateHandle dwDesiredAccess.

  • -. .


4457706

  • CreatePipe.

  • , CreateProcess ( ).

  • CreateProcess, . , , . , .

  • . , , , .

  • ReadFile. ReadFile, , , .

  • .


Npfs named pipe file system

NPFS (Named Pipe File System)

  • Named Pipe File System , named pipes.

  • named pipes (API Win32).

  • RPC NPFS;

  • , .

  • ().


4457706

  • Win32 "CreateNamedPipe".

  • "ConnectNamedPipe", .

  • \\computer_name\pipe\pipe_name "Create File".


4457706

HANDLE CreateNamedPipe (LPCTSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD nMaxInstances, DWORD nOutBufferSize, DWORD nInBufferSize, DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES lpSecurityAttributes

);


4457706

  • lpName ;

  • dwOpenMode , - PIPE_ACCESS_DUPLEX, PIPE_ACCESS_INBOUND, PIPE_ACCESS_OUTBOUND ;

  • dwPipeMode (PIPE_TYPE_BYTE PIPE_TYPE_MESSAGE

  • nMaxInstances ;

  • nOutBufferSize nInBufferSize ;

  • nDefaultTimeout / ;

  • lpSecurityAttributes SECURITY_ATTRIBUTES, .


4457706

BOOL ConnectNamedPipe (HANDLE hNamedPipe,LPOVERLAPPED lpOverlapped

);

BOOL DisconnectNamedPipe (HANDLE hNamedPipe

);


4457706

  • , ConnectNamedPipe () .

  • , , . ConnectNamePipe , , , , OVERLAPPED , ConnectNamedPipe.

  • DisconnectNamedPipe.

  • , CloseHandle ().


4457706

BOOL ReadFile/WriteFile (HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead,LPOVERLAPPED lpOverlapped

);


4457706

  • "ReadFile" "WriteFile".

  • . N- , N- "CreateNamedPipe" ( ).

  • "CloseHandle". "DisconnectNamedPipe".


4457706

- ()

HANDLE hPipe = CreateNamedPipe("\\\\.\\pipe\\PipeSrv",PIPE_ACCESS_DUPLEX | WRITE_DAC, PIPE_TYPE_BYTE,1,100,100,100,NULL);

if (hPipe==INVALID_HANDLE_VALUE) {//

}

ConnectNamedPipe(hPipe,NULL);

DWORD lpBuf; char cName[100];

ZeroMemory(&cName[0],sizeof(cName));

strcpy(&cName[0],"Hello world!");

WriteFile(hPipe,&cName,sizeof(cName),&lpBuf,NULL);

DisconnectNamedPipe(hPipe);

CloseHandle(hPipe);


4457706

- ()

. ReadFile WriteFile, . . CreateFile, : \\ServerName\pipe\PipName.

//pName = \\ServerName\pipe\PipSrv

HANDLE hFile = CreateFile(pName,GENERIC_READ | GENERIC_WRITE, 0,NULL,OPEN_EXISTING,0,NULL);

if (hFile==INVALID_HANDLE_VALUE) {//

}

char str[100];DWORD lpBuff;

ZeroMemory(&str[0],sizeof(str));

ReadFile(hFile,str,sizeof(str),&lpBuff,NULL);

printf("Server sent:\n%s",str);

CloseHandle(hFile);


Mailslots

(MailSlots)

  • . - , . , . , , . .

  • - , . . , , . , .


4457706

Mailslot , (IPC). (), , ().


4457706

  • Mailslot , .

  • Mailslot , . , , Win32.

  • Mailslot . , , Mailslot, .

  • Mailslot .


4457706

  • Mailslot , : \\.\mailslot\[path]name Mailslot , , , mailslot . . . Mailslot:

  • \\.\mailslot\Test.msl \\.\mailslot\SampleDir\Sample


4457706

  • Mailslot, . , , , . Mailslot, Mailslot: \\ComputerName\mailslot\Test.msl ComputerName , Mailslot.

  • Mailslot , , Mailslot : \\DomainName\mailslot\Test.msl DomainName , , Mailslot. Mailslot , Mailslot : \\*\mailslot\Test.msl


4457706

,

  • MailSlot c , , MailSlot. MailSlot, . , MailSlot. , MailSlot MailSlot. MailSlot , ; MailSlot.

  • MailSlot , MailSlot. , MailSlot .


4457706

HANDLE CreateMailslot (

LPCTSTR lpName, //

DWORD nMaxMessageSize, // //

DWORD lReadTimeout, // - //

LPSECURITY_ATTRIBUTES lpSecurityAttributes

//

);


4457706

  • , ,

  • \\\mailslot\[]

  • .

  • \\\mailslot\[]

  • \\*\mailslot\[]


4457706

HANDLE hSlot = NULL;

hSlot = CreateMailslot ("\\\\computername\\mailslot\\messngr", 0, MAILSLOT_WAIT_FOREVER,NULL);

if (hSlot != INVALID_HANDLE_VALUE)

{char buffer[255]; DWORD nBytesRead;

ReadFile(hSlot, &buffer, 255, &nBytesRead, NULL);

}


4457706

HANDLE hSlot = CreateFile(("\\\\computername\\mailslot\\messngr",GENERIC_WRITE, FILE_SHARE_READ, NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);

if (hSlot != INVALID_HANDLE_VALUE)

{char buf = "From\0\To\0Message\0";uint cb = sizeof(buf);WriteFile(hSlot, buf, cb, &cb, NULL);

}


Mailslot

mailslot

  • p, p p . pp-pp , (pp BWCronServerMailSlot). pp- pp (BWCronClientMailSlot) pp pp. pp pp . pp . pp , pp .

  • "-pp" , pp, , pp - . ( pp pp. , , , pp).


Mailslot1

mailslot

MSDN , , INVALID_HANDLE_VALUE


4457706

BOOL GetMailslotInfo (

HANDLE hMailslot, //

LPDWORD lpMaxMessageSize, //

LPDWORD lpNextSize, //

LPDWORD lpMessageCount, //

LPDWORD lpReadTimeout //

);


4457706

BOOLSetMailslotInfo(HANDLEhMailslot, DWORDlReadTimeout );


4457706

(DLL)

, . , , , . , , .


4457706

DLL

#pragma data_seg(".shared")

//

#pragma data_seg()

UsersDll.def:

LIBRARY "UsersDll" SECTIONS .shared READ WRITE SHARED


Rpc remote procedure call

(RPC - Remote Procedure Call)

  • RPC (Remote Procedure Call) API, , .

  • Win32 API RPC Distributed Computing Environment (DCE), Open Software Foundation. Win32 , . RPC .


4457706

( )


4457706

( )

  • "-". - " (listens)" , , - - , , , . .

  • - (stream sockets) (datagram sockets). . , . , - . , . . , TCP , UDP - .


  • Login