Pseudo Code - Assignment 5 | Operating Systems | CS 570, Assignments of Operating Systems

Material Type: Assignment; Class: OPERATING SYSTEMS; Subject: Computer Science; University: San Diego State University; Term: Spring 2004;

Typology: Assignments

Pre 2010

Uploaded on 03/28/2010

koofers-user-t8p-2
koofers-user-t8p-2 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Assignment #5, Spring 2004
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 +id*3; // Status for this turtle (shared memory)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
strncpy(p," R",3); // Set status variable to the current status string
// (access shared memory)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
}
void Boat(void)
{. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .}
pf3

Partial preview of the text

Download Pseudo Code - Assignment 5 | Operating Systems | CS 570 and more Assignments Operating Systems in PDF only on Docsity!

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); } }