process 1
A1: y=x+1
A2: x=y
process 2
B1: y=x+1
B2: x=y
Execution: A1 [B1 B2 (99 times)] A2 B1 [A1 A2 (98 times)] B2 A1 A2
2.2
running --(access some devices such as I/O)--> blocked --(some
interrupt, such as I/O)--> ready --(when it is the time for it to run)
--> running --(time slot ends) --> ready
2.3
Not valid.
It is unknown how the OS scheduler switches the process...
3.1
four philosophers, say A, B, C, D.
fork 1 is placed between A and D
fork 2 is placed between A and B
fork 3 is placed between B and C
the remaining one is fork 4...
A first picks up two forks and eats...thus neither B nor D can eat.
then C picks up ... and eats...but now A puts forks down...
neither B, D can eat...
A and C eat alternatively...and B, D will starve to death...
3.2
Yes...
4.1
ignore it here.
5.1
if (p<c) cost1=p-c; else cost1=c-p;
if (p<c && d ==1) || (p > c&&d == -1) cost1 += y;
if (d=-1) cost2 = y + n-c; else cost2 = n-c;
if (cost1 >= cost2) turn to n;
else turn to p;
5.2
(a) for reliability?
(b) file might be so large...so...
(c) slow, large overhead, and not necessary for small files...
5.3
(a) 1111 1110 0000 0000 0000
(b) 1111 1111 1111 1100 0000
(c) 1000 0001 1111 1100 0000
(d) 1111 1001 1111 1100 0000
5.4
inode contains infomation about a regular file, directory or other file
system object......
Advantages: file name departs from file... it is possible to make
different names point to the same file.
Disadvantages: more space required, slower access
1.1 D
1.2 B
1.3 B
1.4 Printer works much slower than displayer...there will be a lot of
time wasted if CPU waits. With interrupts...CPU can do other things
while waiting for the printer to be ready again.
Because when the OS sends lines of characters to the video display it needs very quick response when the data are ready, the interrupted driven mechanism using blocking can not meet this needs, a pooled driven mechanism using busy waiting may be more proper.
1.5
10/32*2 = 0.625ms
1.6
10/2+5*60/3+10/32*2=105.625
1.7
60*5+2*10/2=310
1.8
It creates a mapping between the address space of a process and a file.
1.9
10.6499ns
5 * 0.99 + 75 * 0.01 * 0.9999 + 5075 * 0.01 * 0.0001 = 5.705??
1.10
5ns
1.11
0 2 7
1.12
7 0 2
1.13
Yes, when the parent terminates before the child process ends...the
parent of the child process become 1(init)
Say a process at level Normal is created, and at the same time a RealTime FIFO is created and at each time interval of the timer there creates a new RealTime FIFO process, therefore the scheduler will never choose the Normal process.
1.14
3
1.15
1
2.1
min = 2
process 1
A1: y=x+1
A2: x=y
process 2
B1: y=x+1
B2: x=y
Execution: A1 [B1 B2 (99 times)] A2 B1 [A1 A2 (98 times)] B2 A1 A2
First process does a read: x->s, s = 0; then jumps to another process to run to the end, and then jumps back to first one doing a wirte: x<-s+1 = 1, then doing so 99 times, got min = 100;
First on do a read, then jumps to second one do the instruction 99 times, then jumps back and do the wirte: x = 1, then first one run to the end: x = 100, then second one do the last time instruction: x = 101 = min + 1
2.2
running --(access some devices such as I/O)--> blocked --(some
interrupt, such as I/O)--> ready --(when it is the time for it to run)
--> running --(time slot ends) --> ready
2.3
Not valid.
It is unknown how the OS scheduler switches the process...
3.1
four philosophers, say A, B, C, D.
fork 1 is placed between A and D
fork 2 is placed between A and B
fork 3 is placed between B and C
the remaining one is fork 4...
A first picks up two forks and eats...thus neither B nor D can eat.
then C picks up ... and eats...but now A puts forks down...
neither B, D can eat...
A and C eat alternatively...and B, D will starve to death...
3.2
Yes...
Need not be protected, because the current variable is only accessed by the scheduler, and there is only one scheduler as the question imply, so it can only be accessed and modified by one process, in other words there will be only one process in this CS all the time.
4.1
ignore it here.
5.1
if (p<c) cost1=p-c; else cost1=c-p;
if (p<c && d ==1) || (p > c&&d == -1) cost1 += y;
if (d=-1) cost2 = y + n-c; else cost2 = n-c;
if (cost1 >= cost2) turn to n;
else turn to p;
5.2
(a) for reliability?
(b) file might be so large...so...
(c) slow, large overhead, and not necessary for small files...
5.3
(a) 1111 1110 0000 0000 0000
(b) 1111 1111 1111 1100 0000
(c) 1000 0001 1111 1100 0000
(d) 1111 1001 1111 1100 0000
5.4
inode contains infomation about a regular file, directory or other file
system object......
Advantages: file name departs from file... it is possible to make
different names point to the same file.
Disadvantages: more space required, slower access
--
Computer Science and Engineering Department
Information Technology School
Fudan University, 200433
ShangHai
China.P.R
> > 1.7
> > 60*5+2*10/2=310
>
>
> 59 * 5 + 2 + 10 + 10 = 317 ms
>
> go to cylinder 60, read the last sector, then go to the 61th cylinder(need
> one switch time), read the first sector.
...what is 2 for in your answer?
Yes, so it should be 59*5+10(read the first sector)+5+10(read the
second) = 320
>
> 1.8
> > It creates a mapping between the address space of a process and a file.
> > 1.9
> > 10.6499ns
>
>
>
> 5 * 0.99 + 75 * 0.01 * 0.9999 + 5075 * 0.01 * 0.0001 = 5.705??
Note that 1 ns = 10^(-9) s...
so ...it is not 5075...it is 5000075...
> > 1.13
> > Yes, when the parent terminates before the child process ends...the
> > parent of the child process become 1(init)
Oh, this is for 1.16
> 2.1
> > min = 2
> >
> > process 1
> > A1: y=x+1
> > A2: x=y
> >
> > process 2
> > B1: y=x+1
> > B2: x=y
> >
> > Execution: A1 [B1 B2 (99 times)] A2 B1 [A1 A2 (98 times)] B2 A1 A2
>
>
> I think it is not same as the mid term exams...... A2 cannot executed
> continuously without A1,......
Why?
ShangHai
China.P.R
0 "assume the exec can have no errors"
2.1
min = 2
process 1
A1: y=x+1
A2: x=y
process 2
B1: y=x+1
B2: x=y
Execution: A1 [B1 B2 (99 times)] A2 B1 [A1 A2 (98 times)] B2 A1 A2I think it is not same as the mid term exams...... A2 cannot executed continuously without A1,......First process does a read: x->s, s = 0; then jumps to another process to run to the end, and then jumps back to first one doing a wirte: x<-s+1 = 1, then doing so 99 times, got min = 100;
First on do a read, then jumps to second one do the instruction 99 times, then jumps back and do the wirte: x = 1, then first one run to the end: x = 100, then second one do the last time instruction: x = 101 = min + 1
6.1
Int I;
If((I = fork()) == 0){
Exec(func, arg, 0);
Printf("exec() error!\n");
}
Else{
Waitpid(I,0,0);
}
indirection of stdin, stdout, stderr first if necessary.
> x = x + 1
> first move x from memory to a register, and increse the content in the
> register before write it back to x.
> It contains at least three instructions.
Yes, I made a mistake...
You need two disk operations to get the first block of the file...as
you need to get the inode first...comparing with linked list structure
for data blocks...
----- Original Message -----From: Huang MaoliangSent: Friday, November 24, 2006 4:28 PMSubject: Re: CS2106 Apr 2002