Mid T
Mid T
Mid T
1.23Which network configuration— LAN or WAN —would best suit the fol-
lowing environments?
a.A campus student union
b.Several campus locations across a statewide university system
c.A neighborhood
a) LAN , b) WAN, c) LAN
Some CPUs provide for more than two modes of operation. What are two
possible uses of these multiple modes?
1. CPUs that support virtualization have one additional mode which
indicates when the virtual machine manager is in control.
2. We can also use so called privileged levels when the system has a
higher privileged level it can execute more instructions.
Give two reasons why caches are useful. What problems do they solve?
What problems do they cause? If a cache can be made as large as the
device for which it is caching (for instance, a cache as large as a disk),
why not make it that large and eliminate the device?
Caches are useful when two or more components need to exchange
data, and transfers at differing speeds. Caches solve the transfer problem.
Large Cache Same Size as Disk
→ this can only occur if:
→ i. the cache and disk have the same size capacity
→ ii. the cache is affordable.
What are some advantages of peer-to-peer systems over client–server
systems?
- services and data can be provided by many peers at once.
- Decentralized services are cheaper to provide since the creator of the service or files does not have to run a
server.
2.15What are the two models of inter-process communication? What are the
strengths and weaknesses of the two approaches?
• Message passing
- strengths: program structures better separated, dangerous operations fire walled
- weaknesses: message passes more slowly, for symmetrical copy operations are to be made
• Shared memory
- strengths: fast and direct
- weaknesses: unexpected behavior when unauthentic programs wrongly accesses the shared
memory segments.
#include <stdio.h>
#include <unistd.h>
[0]
int main() /|\
{ [1] [2] [3]
/ fork a child process / /\|
fork(); [2] [3] [3]
/ fork another child process / |
fork(); [3]
/ and fork another /
fork();
return 0;
}
Including the initial parent process, how many processes are created by the program shown in
Figure 3.32?
#include <stdio.h>
#include <unistd.h>
int main()
{
ANSWER = 16
int i;
for(i=0; i < 4; i++)
fork();
return 0;
}
Explain the circumstances under which the line of code marked printf("Line J" ) in Figure 3.33 will be reached
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
pid t pid;
/* fork a child process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
return 1;
}
if an error occurs in the call to exec(),
else if (pid == 0) { /* child process */
execlp("/bin/ls","ls",NULL); the function returns control and therefor the
printf("LINE J"); line printf("Line J");
} would be performed.
else { /* parent process */
/* parent will wait for the child to complete */
wait(NULL);
printf("Child Complete");
}return 0;
}
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main() A=0
{ B = 2603
pid t pid, pid1; C = 2603
/* fork a child process */ D = 2600
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
return 1;
}
else if (pid == 0) { /* child process */
pid1 = getpid();
printf("child: pid = %d",pid); /* A */
printf("child: pid1 = %d",pid1); /* B */
}
else { /* parent process */
pid1 = getpid();
printf("parent: pid = %d",pid); /* C */
printf("parent: pid1 = %d",pid1); /* D */
wait(NULL);
}
}
What output will be at Line X and Line Y?
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#define SIZE 5
int nums[SIZE] = {0,1,2,3,4};
int main()
{
int i; Because the child is a copy of the parent, any changes
pid t pid; the child makes will occur in its copy of the data and
pid = fork();
won't be reflected in the parent. As a result, the values
if (pid == 0) {
for (i = 0; i < SIZE; i++) { output by the child at line X are 0, -1, -4, -9, -16.
nums[i] *= -i; The values output by the parent at line Y are 0, 1, 2, 3, 4
printf("CHILD: %d ",nums[i]); /* LINE X */
}
}
else if (pid > 0) {
wait(NULL);
for (i = 0; i < SIZE; i++)
printf("PARENT: %d ",nums[i]); /* LINE Y */
}
}
4.4 What are two differences between user-level threads and kernel-level
threads? Under what circumstances is one type better than the other?
Kernel level threads are supported directly by the kernel while the user-level threads are unknown
to the kernel.
Kernel threads are slower to be created and more expensive to maintain then their counterparts
because they require more resources
4.5 Describe the actions taken by a kernel to context-switch between kernel- level threads.
Kernel has to save the context(register values, program counter value, CPU flags, etc.) of currently
executing thread and load the context of the thread which is to be switched in.
4.8 Provide two programming examples in which multi-threading does not provide better
performance than a single-threaded solution.
(1) Any sequential program such as a program calculates an individual tax return.
(2) A program that monitors its own working space such as open files such as the C-shell.
Which of the following components of program state are shared across
threads in a multithreaded process?
a) Register values b) Heap memory c) Global variables d)Stack memory.
Heap memory and global variables are shared across threads.