Mid T

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Describe some of the challenges of designing operating systems for mobile devices compared with designing

operating systems for traditional PCs.


Some challenges include: memory limitation, size of the device, inability for user to upgrade hardware or
components in order to speed up the device.

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

1.21Discuss, with examples, how the problem of maintaining coherence of


cached data manifests itself in the following processing environments:
a.Single-processor systems
b.Multiprocessor systems
c.Distributed systems
a. Single processor system - In a environment where only one process executes at a time this arrangement
poses no difficulties.
b. Multi-processor system - In such environment, a copy of A may exist simultaneously in several caches.
c. Distributed system - In this environment, several copies of the same file can be kept on different
computers that are distributed in space.
Rank the following storage systems from slowest to fastest:
a.Hard-disk drives
b.Registers
c.Optical disk
d.Main memory
e.Nonvolatile memory
f.Magnetic tapes
g.Cache
-
f. magnetic tapes
c. optical disk
a. Hard-disk drives
e. Nonvolatile memory
d. Main memory
g. Cache
b. Registers

What are the three main purposes of an operating system?


• To provide an environment for a computer user to execute programs
on computer hardware
• To allocate the separate resources of the computer as needed to
perform the required tasks.
• As a control program, supervision of the execution and management of the operation and
control of I/O devices.
Which of the following instructions should be privileged?
a.Set value of timer.
b.Read the clock.
c.Clear memory.
d.Issue a trap instruction.
e.Turn off interrupts.
f.Modify entries in device-status table.
g.Switch from user to kernel mode.
h.Access I/O device
The following operations need to be privileged: set value of timer, clear
memory, turn off interrupts, modify entries in device-status table, access
I/O device. The rest can be performed in user mode.

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.

Describe some distributed applications that would be appropriate for a


peer-to-peer system.
Common distributed applications include file-sharing networks, multimedia streams such as a video chat,
cryptocurrency, and anonymous web browsers.
Why do some systems store the operating system in firmware, while
others store it on disk?
For certain devices, such as embedded systems, a disk with a file system
may be not be available for the device. In this situation, the operating
system must be stored in firmware.
List five services provided by an operating system, and explain how each
creates convenience for users. In which cases would it be impossible for
user-level programs to provide these services? Explain your answer.
Program execution: The operating system loads the contents (or sections) of a file into memory
and begins its execution.
I/O operations: It is necessary to communicate with disks, tapes, and other devices at a very low
level.
File-system manipulation: There are many details in file creation, deletion, allocation, and naming
that users should not have to perform.
Communications: Message passing between systems requires messages to be turned into packets
of information, sent to the network controller, transmitted across a communications medium, and
reassembled by the destination system.
Error detection: Error detection occurs at both the hardware and software levels. At the hardware
level, all data transfers must be inspected to ensure that data have not been corrupted in transit.
2.21How are iOS and Android similar? How are they different?
The similarities between iOS and Android are that both are build on existing
kernels, provide frameworks for developers and have architecture that uses
software stacks. iOS it is coded in Objective-C, ANDROID is coded in JAVA.
2.3What system calls have to be executed by a command interpreter or shell
in order to start a new process on a UNIX system?
A fork() system call and an exec() system call need to be
performed to start a new process. The fork() call clones the currently
executing process, while the exec() call overlays a new process based
on a different executable over the calling process. Creation of the task, copying
information.
2.13Would it be possible for the user to develop a new command interpreter
using the system-call interface provided by the operating system?
Yes any user who knows how to use system calls should be able to create a
new command interpreter.

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.

2.20What are the advantages of using loadable kernel modules?


3.10Explain the role of the init (or system) process on UNIX and Linux
systems in regard to process termination.
Init is the ancestor of all other processes (it can be a direct or indirect ancestor) and it adopts all
orphaned processes. Init then periodically invokes wait() in order release the orphan’s PID and
process-table entry.
Including the initial parent process, how many processes are created by
the program shown in Figure 3.31?

#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;
}

Give an example of a situation in which ordinary pipes are more suitable


than named pipes and an example of a situation in which named pipes
are more suitable than ordinary pipes
Ordinary pipes work better with simple communication. Named pipes work better when several
processes need to write messages. Ordinary pipes allow communication between parent and child
processes, while named pipes permit unrelated processes to communicate.

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;
}

What are the pid values?

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

You might also like