

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: OPERATING SYSTEMS; Subject: Computer Science; University: San Diego State University; Term: Spring 2004;
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Assignment #5, Spring 200 4
Pseudo code for part A
File p51.cpp:
// char *sts[N]; // Out-comment the old definition of the status table
Create shared memory for the new status table: HANDLE smh = (HANDLE) 0xffffffff; HANDLE mh = CreateFileMapping(smh,0,PAGE_READWRITE,0,15,"status"); char *sts = (char *) MapViewOfFile(mh,FILE_MAP_WRITE,0,0,0);
A challenge: How can you check the status of successful/unsuccessful execution of the system calls in file scope?
void main () {
................................ Create child process s51 (the server) (Use STARTUPINFO si to force s51 to use the same standard output as p51) CreateProcess("s51.exe",......&si, &pi) ................................ ................................ TerminateProcess (pi.hProcess,1); // Terminate the server when finished }
void Turtle(DWORD id) {............................... char p = sts +id3; // Status for this turtle (shared memory)
............................... strncpy(p," R",3); // Set status variable to the current status string // (access shared memory) ............................... }
void Boat(void) {.............................. .}
File s51.cpp (Server process)
Create shared memory for turtle status: HANDLE smh = (HANDLE) 0xffffffff; HANDLE mh = CreateFileMapping(smh,0,PAGE_READWRITE,0,15,"status"); char *sts = (char *) MapViewOfFile(mh,FILE_MAP_READ,0,0,0);
char answer(char,char*); // External function
void main () { char *q = {"How are you?"}; // Question for turtles int id; // Turtle ID char *p; // Pointer to status string (like "SR", "WL")
for (;;) // Question-answer loop { id = rand()%N; // pick a turtle p = sts+id*3; // Set the status pointer
cout << "Turtle "<<id<<" has status " << p << " answers: "" << answer(q,p) << """ << endl;
Sleep(800); } }