Question: Operating Systems ( Homework #1) NOTE: Please provide a hand written solution . A soft copy or computer printed version will not be accepted. You
Operating Systems (Homework #1)
NOTE: Please provide a hand written solution. A soft copy or computer printed version will not be accepted. You must submit ONE copy of homework per group.
Q1 (50):
Q2(30): Please draw the memory layout of all the process created by the following program when the process is at LINE A. Explicitly show all the memory regions (text, data, stack and heap) for each process and display the variables and their respective values as stored in each region.
Also, what will be printed on the screen at the end of this program?
#include #include #include
int SIZE = 4; int k=10;
void printIt(int *m) { int i=0; for (i=0; i printf("%d,",m[i]); } printf(" "); // LINE A }
void increment(int* a, int divider) { int i=0; for (i=0; i if (a[i]%divider==0) { a[i]++; } } printIt(a); }
void compute(int p) { int* c = (int *)malloc(sizeof(int)*SIZE); c[0]=10; c[1]=12; c[2]=11; c[3]=18; increment(c, p); }
void main() { compute(3); } |
Q3 (20): Please draw the memory representation of all the processes created by running the following program when both processes are at LINE A? Explicitly show all the memory regions (text, data, stack and heap) for each process and display the variables and their respective values as stored in each region.
Also, what will be printed by this program on the screen when all the processes are finished?
#include #include #include
void foo(int p) { p++; // LINE A } void main() {
pid_t pid; int k=600; int m=100;
pid = fork(); k++;
if (pid==0) { k++; m++; foo(m); printf("child process:k=%d,m=%d ",k,m); } else { foo(m); printf("parent process waiting for child ... "); wait(NULL); printf("parent process:k=%d,m=%d ",k,m); } } |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
