Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: Operating Systems Practice Problems
Description: a course that introduces the theoretical and practical issues underlying an operating system's structure and operation. Topics include process and thread creation and management, scheduling, concurrent, multi-threaded programming and synchronization, deadlock, memory management, viritual memory, and computer security. Concepts are demonstrated using the C and Java programming languages in a UNIX environment. This course assumes no prior experience with C, Java, or UNIX.

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


Introduction
1
...

2
...

3
...

True
4
...

1) Open-source (free) [not Windows]
2) Multiuser
3) Interactive
5
...
Hint: it contains seven layers of
concentric circles
...
What are the two primary interprocess communication mechanisms used in UNIX and C
programming?
1) Shared Memory
2) Message Passing

7
...
txt", "r");
Draw the data structure to which fptr points and describe

each field of it
...
When is an entry in the system file table freed?
When the count of the number of file descriptors becomes 0
9
...
What does the following code do?
while((n=read(fd, buf, bufsize)) > 0);

read will return a value of the number of bytes read, and if the value is 0 or less, it
will exit the loop (bufsize = 0 or error)
11
...

????
12
...
For full credit,
your program must read from standard input and file input (with one or more files) and
check for all possible errors, as demonstrated in class
...
What problem may occur with the following code?
#include ...
h>

Commented [KS1]: #include ...
h>
static int
cat_fd(int fd) {
char buf[4096];
ssize_t nread;
while ((nread = read(fd, buf, sizeof buf))
> 0) {
ssize_t ntotalwritten = 0;
while (ntotalwritten < nread) {
ssize_t nwritten =
write(STDOUT_FILENO, buf + ntotalwritten,
nread - ntotalwritten);
if (nwritten < 1)
return -1;
ntotalwritten += nwritten;
}
}
return nread == 0 ? 0 : -1;
}
static int
cat(const char *fname) {
int fd, success;

int main (int argc, char** argv) {
char lastname[24];

if ((fd = open(fname, O_RDONLY)) == -1)
return -1;

if (argc < 2) {
fprintf (stderr, "USAGE: %s string\n", argv[0]);
exit (1);
}
strcpy (lastname, argv[1]);
exit (0);
}

Describe how you would need to modify this program to fix the problem and then show
the corrected code
...
Give the value of argc in a
...
/a
...

1 – redirection doesn’t count as program arguments
15
...
Do not use the [ or ] characters anywhere in
your program
...
Write a complete C program which accepts three files as command-line arguments
...
The program computes the value of the base
raised to the exponent, and prints the resulting product to the file given by the third
command-line argument
...

Commented [KS2]: int
main(int argc, char *argv[])
{
int nflag;
/* This utility may NOT do getopt(3)
option parsing
...

Use argv[1, 2, &3], if statements, fprintf(stderr, “Error”), exits, etc
...


What is a process?
A process is a program in execution
...

Draw a diagram illustrating the logical layout of a process image in main
memory
...
Clearly label all sections and aspects
...


3
...
Clearly,
label both state nodes and directed edges
...


4
...


6
...


8
...


What is multiprogramming?
Multiprogramming is when multiple processes are kept in main memory
and contend for the CPU with the goal of reducing the time the processor
is idle
...

What is a context switch?
Each process change requires a context switch which is purely overhead
(i
...
, no useful work is being accomplished); switching the CPU to
another process requires i) saving the state of the old process and ii)
loading the state for the new process
...

What is an interrupt?
An interrupt is a notification of an event, such as completion of I/O (e
...
,
read or write), error condition (e
...
, divide by zero), request for an OS
service (e
...
, in response to a system call), generated by hardware or
software; once loaded, an OS waits for an event to occur; events are
signaled by interrupts; therefore, an OS is event-driven (or interruptdriven) system

10
...

Hardware or software
11
...

Error condition (dividing by 0)
12
...

Software develops signals
...
Signals occur asynchronously
...

Asynchronous signals are signals that you cannot predict when they will
occur
...
Hardware devices generate interrupts asynchronously
...

15
...
How do interrupts/signals add concurrency to a program?
They are quick to be resolved, do not count on correctness of interrupted
computation, and do not get confused by multiple interrupts
17
...
Adding more main memory to a computer system makes programs run
faster
...

More main memory means more processes that can be kept in main
memory, and more jobs to contend for the CPU
...
If there are too many jobs, more
main memory will not make the programs run faster – only a faster CPU
will be able to enhance the speed
...
(fill in the blank)
Adding more main memory to a computer system increases the degree of
multiprogramming
...
Assume POSIX guarantees that the function mystery is async-signal
safe
...

What else does this imply about mystery?
It is guaranteed to not interfere with operations that are being
interrupted
...
(true / false) Since POSIX guarantees read to be async-signal safe, we
need not restart read if it is interrupted by a signal
...
Explain the role played by signals in non-blocking I/O (also
called asynchronous I/O)
...
These are used as indicators/notifications/interrupts
...
(true / false) Non-blocking I/O is not possible without the use of
interrupts/signals
...
How does fork affect the system file table?
25
...


(true / false) The buffer written by printf is not duplicated by fork
...

#include ...
h>
main() {
fork(); /* fork number 1
fork(); /* fork number 2
fork(); /* fork number 3
printf ("pid: %ld, ppid:
getppid());
}

*/
*/
*/
%ld\n", (long) getpid(), (long)

Trace this program to determine how many processes are created
...
Draw a graph which shows how the processes created are
related
...
The original
process will contain 0 and the process created by the first fork will contain 1
...
Each arrow should
point in a downward direction
...

8 forks, 0, 1, 2, 2, 3, 3, 3, 3
27
...
h>
#include ...
h>
int main() {
pid_t childpid = 0;
int i;
for (i = 1; i < 4; i++)
if ((childpid = fork()) == -1)
break;
return 0;
}

Trace this program to determine how many processes are created
...
Draw a directed graph which shows how the processes created
are related
...
You may assume the pid of the original process is 0 and that pid's are
assigned in increasing order of process creation, (i
...
, 1, 2, 3,
...
Each arrow should point in a
downward direction
...
You must only add code
to the above program; you must not remove any code
...
What output is generated by the following program?
#include ...
h>>
main() {
printf ("Zippy Yay Cool");
fork();
}

29
...

Formally, it is expressed as
fib_0 = 0
fib_1 = 1
fib_n = fib_{n-1} + fib_{n-2}
...
The processes must terminate in reverse order of
creation
...
For instance,
$
0
$
0
$
0
$
0
$
0
$
0
$
0


...
out
1

...
out
1 1

...
out
1 1 2

...
out
1 1 2 3

...
out
1 1 2 3

...
out
1 1 2 3

...
out
1 1 2 3

Commented [KS3]: #include ...


Consider the following C program
...
h>
#include ...
");
return 1;
}
fprintf (stderr, "A");
childpid = fork();
if (childpid == 0)
{
fprintf (stderr, "B");
childpid = fork();
}
}
return 0;
}

How many processes does this program spawn (include the original process in
your count)? Give a brief explanation of how you arrived at your answer
...
1st fork only forks
twice, and the 2nd & 3rd forks will for 10 times due to the for loop
...
Write a complete C program which creates a chain of n (given as a
command-line argument) processes which terminate in reverse order of
creation
...

32
...

True
33
...

True
34
...

False

35
...
Give a complete command
line to set the permissions of logutil so that it would be readable by you,
writable by you and your group, and executable by others, without giving any
extraneous permissions
...
List three types of file information stored in a file's inode
...

37
...

Filename
38
...

39
...

40
...

41
...

False, switch zombie and orphan
42
...
h>
#include ...

else {
wait (&status);

...
Consider the following:
A process fully terminates when
o its parent has executed wait(&status), and
o it exits or is killed by a signal (e
...
, )
...

3
...
What happens if they occur in the reverse of normal order?
5
...
Consider the following series of command lines and outputs (executed in
this order):
1
2
3
4
5
6
7
8
9
10
11

export PAGER=less
EXINIT="showmode showmatch ruler"
ksh
echo $PAGER
echo $EXINIT
export A=10
exit
echo $A

0
...
What is printed on line 5?
2
...
What is printed on line 11?
45
...

Do not re-implement ls
...
Do not use
the system call system in your program
...
What would you do to setup your environment such that files are created
readable by only you, your group, and others, but writable by only you and
your group, without giving any extraneous permissions, in such a way that this
change would be in effect each time you logged in?
ls
Title: Operating Systems Practice Problems
Description: a course that introduces the theoretical and practical issues underlying an operating system's structure and operation. Topics include process and thread creation and management, scheduling, concurrent, multi-threaded programming and synchronization, deadlock, memory management, viritual memory, and computer security. Concepts are demonstrated using the C and Java programming languages in a UNIX environment. This course assumes no prior experience with C, Java, or UNIX.