1. Procese Windows; comunicaţii prin pipe şi IPC 2
1. Procese Windows; comunicaţii prin pipe şi IPC 2
1. Procese Windows; comunicaţii prin pipe şi IPC 2
- TAGS
- procese
- pipe
- www.cs.ubbcluj.ro
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
}<br />
}<br />
<strong>Procese</strong> <strong>Windows</strong>; <strong>comunicaţii</strong> <strong>prin</strong> <strong>pipe</strong> <strong>şi</strong> <strong>IPC</strong> - 26 -<br />
pc = pm->s;<br />
<strong>prin</strong>tf("%d\n",pm->lung);<br />
for (i = PLUS; i < pm->lung; ) {<br />
<strong>prin</strong>tf("%d %s\n", i, pc);<br />
i += strlen(pc) + 1;<br />
pc += strlen(pc) + 1;<br />
}<br />
In sfarsit vom prezenta programele <strong>prin</strong>cipale.<br />
Programului <strong>prin</strong>cipal al serverului este dat in shms.cpp:<br />
#include <br />
#include <br />
#include "shmmesaj.h"<br />
#include "shmReadWrite.cpp"<br />
#include "dir.cpp"<br />
#include "shmparinte.cpp"<br />
main() {<br />
HANDLE shm, semafor, cerere;<br />
Segment *segment;<br />
fclose(stdin);<br />
fclose(stdout);<br />
shm = CreateFileMapping((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,<br />
0, sizeof(Segment), "SegmentMemoriePartajata");<br />
segment = (Segment*)MapViewOfFile(shm, FILE_MAP_WRITE, 0, 0,<br />
sizeof(Segment));<br />
segment->tip = 0;<br />
segment->pid = GetCurrentProcessId();<br />
semafor = CreateSemaphore(NULL, 1, 1000, "OcupaSegment");<br />
cerere = CreateSemaphore(NULL, 0, 1000, "ExistaCerere");<br />
parinte(segment, semafor, cerere);<br />
// Prin specificul problemei noastre cuncrete, nu se va ajunge la<br />
// instructiunile de mai jos. Le scriem totusi pentru exemplificare.<br />
CloseHandle(cerere);<br />
CloseHandle(semafor);<br />
UnmapViewOfFile(segment);<br />
CloseHandle(shm);<br />
}<br />
Sursa clientului este data in shmc.cpp:<br />
#include <br />
#include <br />
#include "shmmesaj.h"<br />
#include "shmReadWrite.cpp"<br />
#include "shmfiu.cpp"<br />
main() {<br />
HANDLE shm, semafor, cerere;<br />
Segment *segment;<br />
shm = OpenFileMapping(FILE_MAP_ALL_ACCESS, TRUE,<br />
"SegmentMemoriePartajata");<br />
segment = (Segment*)MapViewOfFile(shm, FILE_MAP_WRITE, 0, 0,<br />
sizeof(Segment));<br />
semafor = OpenSemaphore(EVENT_ALL_ACCESS, TRUE, "OcupaSegment");<br />
cerere = OpenSemaphore(EVENT_ALL_ACCESS, TRUE, "ExistaCerere");<br />
fiu(segment, semafor, cerere);<br />
CloseHandle(cerere);<br />
CloseHandle(semafor);<br />
UnmapViewOfFile(segment);<br />
CloseHandle(shm);