Put the system calls in order for use in a typical shared-memory program:
- shm = shmat(id)
- strcat(shm)
- shmctl(id, IPC_RMID)
- shmdt(shm)
- id = shmget(KEY, SIZE, PERMS)
Assume the following code is compiled and run:
int n=0; /* global variable */
main() {
fork();
doit();
n = n + 1;
printf("n: %d\n", n);
}
void doit(void) {
int x=0;
x = x + 1;
printf("x: %d\n", x);
}
Assume all system calls succeed.
fork() call is changed to a spawn()
call that creates an additional thread in the same process
instead of a new process. Now, what are all the possible outputs
from 1 of the processes?
For the SOS SelectProcessToRun() sample below,
show how you would modify it to support two processes. Assume each
processor has a variable named p1 and p2
respectively. Use cli() and sti() (as
in the Linux kernel) for any required synchronization.
int SelectProcessToRun() {
static int next_proc = MAX_PROCESSES;
if (current_process > 0
&& pd[current_process].slotAllocated
&& pd[current_process].state == READY
&& pd[current_process].timeLeft > 0)
return current_process;
for (int i=1; i < MAX_PROCESSES; i++) {
next_proc++;
if (next_proc >= MAX_PROCESSES)
next_proc = 1;
if (pd[next_proc].slotAllocated && pd[next_proc].state == READY) {
pd[next_proc].timeLeft = TIME_QUANTUM;
pd[next_proc].state = RUNNING;
return next_proc;
}
}
return -1;
}
Fragmentation:
Consider the following page reference string:
5,2,3,7,6,5,2,3,7,2,3
Assume pure demand paging so your first unique pages will all cost one fault each. Assume the process has a 4 frames at all times.
Consider a demand-paging system with the following time-measured utilizations:
CPU utilization: 99%
Paging disk: 10%
Other I/O devices: 8%
Which (if any) of the following will (probably) decrease CPU utilization?
Suppose that a 32-bit virtual address is broken up into three fields: a, b, and c. The first two, a and b, are used for a two-level page table system. The third field, c, is the offset. If a, b, c are 4, 2, 4, respectively. How large is each page? How many pages can be in a logical address space?
What is the role of the device independent layer of a device driver?
Return
to the CS3013 Home Page