CS2106 Apr 2002

1 view
Skip to first unread message

Li Yi

unread,
Nov 23, 2006, 11:55:58 PM11/23/06
to Hexakios
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.
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
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)
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

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

guozhang wang

unread,
Nov 24, 2006, 12:36:11 AM11/24/06
to Hexa...@googlegroups.com


在06-11-24,Li Yi <liy...@gmail.com> 写道:

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.
 
I think you got the question wrong...
 
here's my answer:

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
 
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.

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
 
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 A2
 
I 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


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

Li Yi

unread,
Nov 24, 2006, 2:14:02 AM11/24/06
to Hexakios

guozhang wang wrote:

> > 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?

guozhang wang

unread,
Nov 24, 2006, 2:19:25 AM11/24/06
to Hexa...@googlegroups.com
in mid term it's "y = x+1, x = y", so this two A1 A2 can be executed at any order like a1, a2*99, a1*99,a2, but here every a1 must followed by a2, until a a2 is done, another a1 cannot be executed, i think...

在06-11-24,Li Yi <liy...@gmail.com> 写道:
ShangHai
China.P.R

Li, Yi

unread,
Nov 24, 2006, 2:26:32 AM11/24/06
to Hexa...@googlegroups.com
You are saying that x=x+1 is atomic?
Then ... it is 200...isn't it?

guozhang wang

unread,
Nov 24, 2006, 2:26:52 AM11/24/06
to Hexa...@googlegroups.com
no, it's not atomic, but it's executing order can not be changed, what I'm saying is that you can not leave current instruction half done and move to do the next instrcution, like a2, then a2, a2, a2.....

在06-11-24,Li, Yi <s060...@nus.edu.sg> 写道:

Li, Yi

unread,
Nov 24, 2006, 2:34:15 AM11/24/06
to Hexa...@googlegroups.com
Did I do that?

Huang Maoliang

unread,
Nov 24, 2006, 2:39:51 AM11/24/06
to Hexa...@googlegroups.com
guozhang wang 写道:
1.6
the parent process of a process change only when the process exit before the child process exit. In that case, the new parent process is init. In other case, the parent process has no change to desert it children.

 
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 A2
 
I 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


I think it can be 2.
x = x + 1 ->   mov x, %eax     a
               add %eax, 1     b
               mov %eax, x     c
   the first process executes up to b and is switched to the second one which execute a,b,c 99times. When the first one executes again, it executes c to write 1 to x. At this time, it is the turn of the second one. It execute up to b and switched to the first one, which will exit this time. when the second one runs again, it writes 2 to x.
the disadvantages, why slower access.

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.



Huang Maoliang

unread,
Nov 24, 2006, 2:43:37 AM11/24/06
to Hexa...@googlegroups.com
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.

guozhang wang 写道:

Li Yi

unread,
Nov 24, 2006, 3:08:21 AM11/24/06
to Hexakios

Huang Maoliang wrote:

> 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...

Li Yi

unread,
Nov 24, 2006, 3:11:48 AM11/24/06
to Hexakios
> > 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
> >
> the disadvantages, why slower access.

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...

Huang Maoliang

unread,
Nov 24, 2006, 3:17:27 AM11/24/06
to Hexa...@googlegroups.com

compared with FAT, EXT2 is more efficent.
FAT needs one access to the disk to get the directory entry, then chains down the FAT to find a particular block.

Li Yi 写道:

Huang Maoliang

unread,
Nov 24, 2006, 3:28:03 AM11/24/06
to Hexa...@googlegroups.com

Li, Yi

unread,
Nov 24, 2006, 3:40:05 AM11/24/06
to Hexa...@googlegroups.com
Right. But EXT2 is not that effecient when reading the first block, or, when I want to retrieve all of the file...but it has great advantage in random access over FAT.
----- Original Message -----
Sent: Friday, November 24, 2006 4:28 PM
Subject: Re: CS2106 Apr 2002

Reply all
Reply to author
Forward
0 new messages