Unit One Objectives...

jaspersugarlandSoftware and s/w Development

Dec 14, 2013 (3 years and 8 months ago)

90 views

Chapter 2


1)

Define Operating System (kernel)

a.

Starts automatically when computer is turned on, waits
for user to interact with it.

b.

Hides all of the hardware details through an “abstract”
layer.

c.

The operating system manages most aspects of the
machine, such
as memory and process management. It
manages every small detail that the computer needs to
complete in the background to make things run.

2)

Explain the role of the kernel and name six “agents” that make
up the operating system (OS) application program interf
ace
(API).

a.

The role of the kernel is to create a framework within
which other applications run. It provides memory
management, users, groups, etc. The OS handles
interrupts, device management, and any other system
events (laptop closed, wireless network fo
und, etc).

b.

Six agents

(Straight from Dr. Maginnis)
:

i.

Network Protocol Stack

ii.

File Manager

iii.

Memory Manager

iv.

Process Manager

v.

Time Manager

vi.

Inter
-
process Communication

3)

Describe a hypervisor and its design tradeoffs

a.

A hypervisor is a virtual machine manager. Basica
lly, it
operates in between the OS and the physical hardware
(because it manages multiple OS’s).

b.

Domain 0


the operating system we are running
currently

c.

Any other domains are the additional OS’s loaded by the
VM.

d.

Examples: XenDesktop, VMWare, Virtualbox

4)

Describe the concept of a Unix environment and the bash “set”
vs. “env” commands.

a.

First things first: BASH stands for “Bourne Again Shell”,
which just means the command line. So he’s asking what
typing these commands into the command line will do.

b.

Unix has

a bunch of environmental variables that every
application can access to determine information about the
system.

These are called “environmental” variables and
they are always in all caps.

i.

env



lists all of the “enviromental variables” stored

ii.

set



displays every inherited function and variable
stored in the environment, not just the
Enviromental variables.

5)

Explain how /etc/passwd, /etc/shadow, and /etc/group are
used to implement the file protection scheme of

rwxrwxrwx
and explain why network daem
ons such as mail, syslog, etc.
have user accounts.

a.

/etc/passwd
:
Every user of the system has the following
qualities, which are stored in the /etc/passwd file:

i.

Login name

ii.

User ID

iii.

Group ID

iv.

Home directory

v.

Login shell

vi.

Password (Encrypted)


Example:

loginname
:
encrypted password
:
uid
:
gid
:
comment about
user
:
home directory
:
default shell

b.

/etc/shadow

:
Sometimes the password is stored in the
/etc/shadow file, for security reasons.

c.

/etc/group
:
For administrative purposes (mostly for
controlling access to files), users

are organized into
groups. Every group is stored in the /etc/group file, and
includes the following information:

i.

Group name

ii.

Group ID

iii.

User list



names are
separated by commas

d.

File protection scheme:
-
rwxrwxrwx

i.

Each file has an owner (whoever created it) and
settings associated with that file.
r

stands for read,
w

stands for write,
x

stands for execute. The bit of
each of these settings is “1” if its turned on.

ii.

As you can see, there are three
groups

of “settings”
for every file.


1.

First triad: What the owner can do

2.

Second triad: What the group members can do

3.

Third triad: What everyone else can do

6)

The first letter of the long directory listing contains the file type:
-
, d, p, s, l, c, and b. Describe e
ach type.

a.


-
“ is just a normal file

b.

“d” is a directory (or folder)

c.

“p” is a pipe. It connects the output of one process to the
input of another.

d.

“s” is socket. Allows communication between two
processes

e.

“l” is a symbolic link. This is a reference to anot
her file
somewhere else on the system

f.

“c” is a character device. This is an external device that
provides a stream of input.

g.

“b” is a block device. These devices are randomly
accessible.

7)

Describe the naming, structure, and the sequential nature of the
Unix

file protection mechanism. And be able to explain the
following protections.

a.

drwxrwxrwx

|
This file is a directory. Any user can read,
write, or execute operations on it.

b.


rw
-
rw
-
rw
-

| This is a normal file. Every user has the
ability to read or write to
it, but no one has the ability to
execute it.

c.


rwx
-
r
-
x
-
r
-
x

| This is a normal file. Every user can read
or execute the file, but only the owner can write to it.

d.

drwx
------

| This file is a directory. Only the owner can
read, write, or execute it.

e.

drwxrw
-
rw
-

| This file is a directory. Everyone can read
or write to it, only the owner can execute operations on it.

f.


rwsr
-
x
-
r
-
x

| because there is an s instead of x, that
means the owner can execute the file, as well as set the gid
or uid associated with the file
. Everyone can read and
execute the file, but only the owner can write to it.

g.


rwxr
-
s
-
r
-
x

|
similarly
, everyone here can read or
execute. The owner can write. Anyone in the group can
change the uid or pid associated with the file.

h.

drwxr
-
xr
-
t
| This file is

a directory. Anyone can read or
execute. Only the owner can write. See below to find out
the operation of the t.

i.

The sticky bit is a “t” at the end of the file permissions.
This means that a user can only rename or delete a file if
they have write permiss
ions AND they are the owner or a
super user (root).

8)

Contrast _exit(), exit(), wait(), termination status, exit status.

a.

_exit should be used to exit child processes (or threads).
The reason for this is so that the parent process’s memory
is not interfered
with.

b.

exit() should be used to exit your main thread

c.

wait() should be used to make your thread pause for a
certain amount of time

d.

Similarly, termination process defines the termination of
a child thread as opposed to exit status, which defines the
terminat
ion of your current thread to it’s parent process.

9)

Contrast real user/group ID, effective user/group ID, and
supplemental group ID.

a.

Real


this identifies the user and group to which a
process belongs

b.

Effective


this identifies the permissions a process
has
when it goes to access a file. Usually the same as the Real,
except for when you need elevated permissions.

c.

Supplementary


this identifies other group id’s to which
the process belongs

10)


Describe the init process.

a.

Real ID: 1, Effective ID: 0

b.

Cannot be
killed.

c.

Hand crafted by system boot, starts all other processes

d.

Controls at what level of operation we are running
currently

11)

Define the concept of “path” and explain the “PATH” shell
variable. Bash shell PATH label (shell variable) can be
appended by addin
g the current directory to the search with the
command: PATH=$PATH:.

a.

The “path” environmental variable is simply a list of
directories that the system looks through for
executables
.

12)


Describe the role of mmap() and the arguments private
versus shared.

a.

mmap
() associates a file’s contents with a page
-
aligned
area of memory and reading this area causes the file to be
read into memory.

b.

If the mapping is shared, writing by one process will be
seen by other processes with the same mapped area and
file.

c.

If the map
ping is private, changes will not be seen by
other processes or written to the file on disk.

d.

Anonymous mmap() will map a memory area backed by
unnamed file blocks similar to malloc.

13)


Contrast the commands:

a.

gcc File.c : compiles a C file

b.

gcc File.s :
compiles an assembly language file

c.

gcc

c

o file.o file.s :
compile file.s into file.o, but don’t
create an executable

d.

gcc

S file.c

o file.s : compile file.c into file.s but don’t
assemble the code.

e.

As

a file.s > file.lst : assembly the code in file.s

into
file.lst

14)


Contrast the role of static (ld) versus shared (collect2)
libraries in terms of foot print and image contents.

a.

Both of these are linkers. The ld utility gathers all of the
libraries needed and compiles it into one big executable.
The collec
t2 just links the libraries needed, but goes out
and retrieves them at runtime rather than
during compile
time.

15)

Talk about static vs. dynamic linkers

a.

A static linker mergers the libraries with the main
application, which wastes valuable memory space becaus
e
library routines are loaded for every executable. These
programs are “stand alone” and tend to be immune to
corruption.

b.

A dynamic linker only saves the name of the library
routine and loads the library at runtime. However, there
is no guarantee that the
library is not corrupted and since
every executable is using the same library, if one
executable corrupts a library, it messes up every process.
Dynamic libraries can be distributed without having to
recompile every application that uses it, but this means

that the library could easily be hacked and used
maliciously.

16)

Define and contrast signal terms: “software interrupt”,
“catch”, “ignore”, “default”, “pending”.

a.

One program sends an interrupt to another program

b.

Change the return address for the original pro
gram

c.

Catch is an exception interrupt

d.

Default is just a normal signal

e.

Pending is some pending operation

17)


Contrast “controlling terminal”, “controlling process”,
and “sessions”.

a.

Controlling terminal is the terminal session which
controls a command. Controlli
ng process is the
corresponding process to that command. Session is an
interactive environment in which commands can be
executed.

18)


Contrast the commands “date” and “time”
.

a.

Date gives you information about the date.

b.

Time
is a benchmarking tool

19)


Explain the implementation of /dev /proc /sys and
/dev/ram

a.

These are Linux abstractions that appear to be files but
act as a gateway (via jump tables) to various drivers which
display and manipulate system information and physical
devices.

b.

/dev


device d
rivers

c.

/dev/ram


RAM access

d.

/proc


details of currently running processes and OS
status

e.

/sys


details of hardware configuration


Chapter 3


1)

Define a “system call” and describe three general aspects of any
system call.

a.

A system call is the mechanism by w
hich an application
program requests a service from the OS.

b.

Processor state goes from user mode to kernel mode.

c.

The number of system calls is fixed, each call has a unique
identification number.

d.

Kernels have a special routine or way to gather system call
a
rguments from the suspended user memory space, as
well as read/write user space buffers.

2)

Define “interrupt” processing and explain how trap instructions
emulate interrupts.

a.

At the end of each instruction, the CPU checks for signals
from devices. If a signa
l is present, then the program
counter and processor status word is saved on the stack
which permits returning to the interrupted process.

b.

The CPU responds to a given device request based on
priority of the interrupt; the selected device provides a
memory
address vector containing a pointer to the
interrupt service routine (ISR) which processes the
device’s request.

c.

The CPU loads the vector contents (program counter and
process status word) which begins execution of the ISR.
Upon completion of the ISR, the
CPU uses the stack to
return and continue the interrupted process.

d.

A trap instruction specifies a vector address to transfer
control to another routine. It’s different from a subroutine
call in that a new processor status word is loaded upon
entry to the n
ew routine. The new processor status word
gives the CPU access to I/O instructions and the MMU
which is what makes the kernel work.

e.

Intel has optimized this process with the faster “sysenter”
instruction
.

3)

Explain the implementation of a system call.

a.

The sy
stem service calls a “wrapper” function in the C
library.

b.

The wrapper function moves arguments from the caller’s
stack to CPU registers.

c.

All requests use the same trap instruction, but each
service request is identified with a unique number in the
CPU
register.

d.

The kernel uses the unique number to jump through a
table to the correct routine.

e.

As with interrupts, each function returns to its caller and
to the application.

4)

Explain what is meant by “operating system overhead”, how to
measure it, and how to
minimize it.

a.

Operating system overhead (OSO) is the time it takes to
switch between two process
es

(context switch) which is
available computation time lost to all applications. The
simplest service request requires two context changes:
save application, re
store kernel, save kernel, restore
application in addition to the migration time through the
various library and kernel dispatch routines.

b.

OSO is measured by using the time(1) command to
measure a large number of OS calls and divide time by the
number of c
alls.

c.

The programming minimizes OSO by organizing data into
large blocks before requesting OS services thereby
limiting the number of context switches. This is the
strategy of “f” services that use the block size buffer in
stdio.h for the character I/0.

5)

De
scribe indication, type, and presentation of Unix error
reporting.

a.

Indication: By convention, the Unix kernel returns a “
-
1”
indicating an error occurred. The calling program,
therefore, is required to check the returned value for an
error condition after
every service call.

b.

Type: When a system error does occur, the type of error is
held in the global variable errno, other the value of errno
is said to be undefined. Error types are declared in
/usr/include/sys/errno.h and begin with an “E”.

c.

Presentation: Th
e C library perror function passes along
your error message and prints the strings in errno.h
associated with errno.


Chapter 4


1)

Contrast file descriptor I/O versus stream I/P and give the
tradeoff.

a.

File descriptor I/O uses open(), read(), write(), and
clo
se(). They get or put the user buffer directly into the
kernel.

b.

Stream I/O uses the “f” library calls such a fputs(), fgets(),
etc. They are generally character oriented I/O calls and
get/put user characters in a hi
dden buffer in the stdio.h
header
file.

c.

Stream I/O reduces operating system overhead ny
gathering characters into a block before performing I/O.
File descriptor I/P is for more advanced need where the
user wants to directly control I/O.

2)

Describe each component in the C statement: typedef enum
{F
ALSE, TRUE} Boolean;

a.

Typedef


we are declaring a new type

b.

Enum


The type of variable we are creating is an
enumeration

c.

FALSE, TRUE


these are the available values for our
variable

d.

Boolean


our name for our type

3)

Describe the C macro: #define min(m,n)
((m) < (n) ? (m) : (n))

a.

Describe the flow control.

i.

The macro is replaced with the abbreviated if
-
then
-
else statement using the desired parameters to place
the actual parameters in the C statement. Thus,

m
is less than n, return m, otherwise return n.

b.

The
rest is straightforward

4)

Explain the rational of Kerrisk’s get_num and error handling
routines; contrast errno, error name, and error.h.

5)

Contrast and give examples of file inclusion, macro definition,
macro expansion and computational compilation.

a.

File incl
usion:

i.

#include “myheader.h”

ii.

#include <stdio.h>

b.

Macro definition:

i.

#define VAR=1<lf>

c.

Macro
expansion
:

i.

#define PLUSONE(x) (x+1)
<lf>

d.

Conditional computation:

i.

#define OSX

6)

Define system data types, why are they required, and explain
how they may clash with C l
ibrary function such as printf() and
the solution.

a.

System data types are the types included in the C library
to make our life as programmers easier.

b.

The sizes of fundamental types (not system data types.
These include int, double, etc) may vary from system

to
system, so the C programming language has these types
included with a hardcoded size for compatibility.

c.

Printf accepts both an int and a long type. Because the
system has no way of knowing which type you have
passed to the function, you must explicit i
dentify whether
it is a long or an int, as well as include the correct type in
the string (Ex. %ld or %d).

7)

When writing portable code, describe the adjustments to make
when dealing with initializing structures, using a system macro,
and header files.

a.

When
initializing structures, we must use explicit
assignment statements, like the following.

i.

Struct sembuf s;

ii.

S.sem_num = 3;

iii.

S.sem_op = 01;

iv.

S.sem_flg = SEM_UNDO;

b.

When using a system macro, check that the macro exists
like so:

i.

#ifdef WCOREDUMP

ii.

#endif

c.


When deal
ing with header file across different systems,
one should note that these header files could vary from
system to system. Thus you should denote a header file /*
for portability */ to indicate that it is not required on
Linux or SUSv3, but because some othe
r (especially older)
implementations may require it, we should include it in
portable programs.

8)

Contrast the terms pure code, reentrancy, multiprogramming,
multi
-
tasking, timesharing, and multi
-
user operating systems.

a.

Pure code


A program containing only
instructions,
constants, and memory references relative to the program
counter. In this way, pure code may be executed from
anywhere at any time.

b.

Reentrancy


Use of pure code with a stack for each
program allows one program to be suspended at any point
an
d another program restarted at any point.

c.

Multiprogramming


Two or more programs that run
separately, but cooperate to achieve a common goal such
as the producer/consumer problem.

d.

Timesharing


Two or more independent programs that
have fair and equal acc
ess to the machine.

e.

Multi
-
user


Two or more users may execute one or more
programs in a multi
-
tasking or timesharing environment.

9)

Describe a software object model OS design.

a.

Software object are independent modules which only
accept messages and provide re
plies. What occurs insi
de
an objet is hidden from other
objects.

b.

While processing one message, each object must be able
to suspend the

flow of control so that it may receive and
process other messages.

c.

Each object must duplicate a private multi
-
tasking
mec
hanism.

d.

Dividing the operating system’s functionality among 20 or
so objects generates significant overhead in message
exchanges among objects (25
-
30%) in spite of design
shortcuts.