Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

COMP313 W1 Test 1 2016 Model Answer

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

COMP313 W1 Test 1 2016

MODEL ANSWER
1. The shell has a two-fold containment function. It provides an encapsulated environment to
users and applications. The shell also abstracts the machine even further than the kernel does
and removes from vision all resources that do not pertain to the user that has established the
shell session.
2. (Any 3)
Links (hard) – i-node representing a file stream on storage device. There can be a minimum
of one per file on the file-system.
Device files – block and character device files found in /dev/* to represent I/O hardware on
system.
Pipes – named and unnamed memory buffer for inter-process communication
Sockets – named pipe for inter-node inter-process communication.
3. The owner may: read, write (create/delete), and execute (navigate path).
The owning group may: read and execute (navigate path).
Others may not read, write, or execute.
4. (Any 3 of below, or others)
For example, the location of a user’s personal data is stored in a shell environment variable
called HOME. Another example of an environment variable is the current location of the
shell in the file-system - this variable changes when ever the user changes location and is
called PWD - print working directory. A third useful environment variable is a list of
locations containing programs that the user can run. This variable is called PATH.
5. ; - This is a command separator and can be used to separate a series of sequential commands
so that they can be issued in one go.
command& - Run command as a background process. This means that the process input,
output, and error streams are detached from the shell that the process was launched from and
that the shell is available for interaction - it doesn’t have to wait for a background task to
complete before issuing the next command from the user or program. If you wanted to script
a set of commands that can run simultaneously, you could place an ampersand after each
command in the script.
| - The interconnecting pipe is used instead of a buffer file when you want to redirect the
output of one process to the input of another. Without this operator you would have to
redirect the output of the first process into a file and then redirect the input of the second
process so that the stream comes from that file.
>>, > - The file output redirection comes in two forms. If the double bracket (append mode)
is used then the specified file is created if it does not exist before the data is written to it. If
the file already exists then the data stream is appended to the contents of the file. If the
single bracket (overwrite) is used then the file is overwritten by the new data if it already
exists.
< - The file input redirection operator can be used to provide the contents of an input file to a
program, one line at a time, as an alternative to keyboard input.
6. Linux Boot Process (from BIOS):
0. BIOS - The BIOS checks system hardware components. The only responsibility of the
BIOS in the boot process is to transfer control to first-stage boot loader on the MBR. Not all
machines are PCs, some larger machines have entire firmware operating systems just to
initialise and coordinate their hardware components.
1. First-stage boot loader - Transfer control to second-stage boot loader. This usually resides
on the same file system that the kernel resides in. In UNIX, this is the /boot directory.
2. Second-stage boot loader - The main responsibility of the subsequent boot loader stage/s
is to load the kernel into memory and execute it. There might be more stages before the
kernel is actually loaded though. For example, a third-stage boot loader might be used to
load support for a particular file system. Once the kernel is loaded, the boot loader can do
one more optional task - it can set the initial state of a micro-kernel in memory.
This is done by loading a snapshot of the kernel with all appropriate modules configured
from a ram image file (called initrd in Linux). The first thing the kernel does is mount the
top-level file system as a read-only file system. This is because the kernel is not sure that it
is safe to modify the file system at this point. Whether there was an initrd image or not, the
kernel loads required modules. Once all the modules are loaded and configured, the kernel
transfers control to the principal process of the system. The program of that process is called
init, and it resides on the top-level (root) file system in this location: /sbin/init.
3. /sbin/init - The init process loads all services that are need to keep the operating system
functioning correctly. Once the operating system is initialised, the init process loads user-
space utilities. These processes run in user mode and are required to support users, as
opposed to the operating system. The init process looks in a file that lists file systems and
corresponding partitions. This file is located in the root filesystem, /etc/fstab. Among the
partitions in the list is the root file system which, at this, stage is still mounted in read-only
mode. The root file system is re-mounted in read-write mode. Finally, the init process runs
one or more getty processes. The getty program presents the user with a login prompt, that,
when the user types in the correct username and password, runs a shell process and gives the
user input control over that shell.
7. 3 processes, piped together, with output redirect, running in background
1 – list contents of comp313_marks in /data directory
2 – sort input stream (output stream of 1)
3 – take top 10 lines from input stream (output of 2), and write output to smart_students file
in /data directory.
8. A semaphore is an integer variable, S, and an associated group of waiting processes, Q(S),
upon which only two operations, P and V , may be performed.
P (S) if S ≥ 1 then S = S − 1 else the executing process places itself in Q(S) and goes to
sleep.
V (S) if Q(S) is non-empty then wake up one waiting process and make it available for
execution else S = S + 1.
9. ...
nrfull: semaphore = 0
...
Producer:
...
buff[in]=m
in = in + 1 mod N
...
Consumer:
...
P(mutexC)
P(nrfull)
...
V(nrempty)
V(mutexC)
...
10. A set of processes is in a state of deadlock when every process in the set is waiting for a
resource that can only be released by another process in the set.
A deadlock situation may arise iff the following necessary condition holds:
• circular hold and wait:
There must exist a set of waiting processes {p1 , p2 , . . . , pn } such that p1 is waiting for a
resource held by p2 , p2 is waiting for a resource that is held by p3 , . . ., pn is waiting for a
resource that is held by p1 . The resources involved must be held in a non-sharable mode.
11. ...
12. ...

13. ...

You might also like