Sunteți pe pagina 1din 3

Problem 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . 10 points

Floating point exception due to 34/0. but if we remove this exception there is a deadlock between the
child and the parent process as they both try to read from the pipe.

Problem 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 points
Answer the following questions about different connection types.
(a) (5 points) Describe the general properties of a datagram connection.

A Datagram connection is used when order is less important than timely.
When you don't want the higher overhead of a stream, so that servers can respond to many,
many requests at once very quickly),
When you don't care too much if the data ever reaches its destination.
Datagram protocols like UDP, allows the software to recover from events of packet loss
extremely quickly, by simply ignoring the lost data or re-requesting it sooner than TCP would.
Datagram protocols ignore the missing data (if subsequently-received data supercedes the
data that was lost), re-request the missing data, or request a complete state update to ensure
that the client's state is in sync with the server's.


(b) (5 points) Describe the general properties of a stream connection.

Stream sockets are used when having information in order and intact is important. File
transfer protocols(FTP) are a good example here. You don't want to download some file with
its contents randomly shuffled around and damaged!
Stream socket allows for reading arbitrary number of bytes, but still preserving byte
sequence. In other words, a sender might write 4K of data to the socket, and the receiver can
consume that data byte by byte. The other way around is true too - sender can write several
small messages to the socket that the receiver can consume in one read. Stream socket
does not preserve message boundaries.
A stream socket with TCP at least needs the initial three way handshake to establish the
connection.

(c) (5 points) Describe a situation where using a stream connection over a datagram
connection would be beneficial. Explain why.

A stream connection is beneficial in case where reliability of the data is an issue. As in case of TCP
protocol, reliability is ensured on transport layer. FTP is an example where stream connection is preferred
over datagram as the information must be in order and intact. You don't want to download some file with
its contents randomly shuffled around and damaged!

(c) (5 points) Describe a situation where using a datagram connection over a stream
connection would be beneficial. Explain why.

In VOIP and game protocols Datagram connection serves more benefit then stream connection. If one
packet is damaged or lost, you don't want to wait on the stream protocol (usually TCP) to issue a re-send
request you need to recover quickly. TCP can take up to some number of minutes to recover, and for
real-time protocols like gaming or VoIP even three seconds may be unacceptable! Using a datagram
protocol like UDP allows the software to recover from such an event extremely quickly, by simply ignoring
the lost data or re-requesting it sooner than TCP would.


Problem 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 points

output would be : 0123456789

SYS1 is the server which is bind to port 4444 and SYS2 is the client which is sending the message of
length 10 to SYS1. Server waits to receive the message after binding the port and receives the message
from the SYS2 using the socket. Datagram socket type is used in this scenerio, which implies a UDP
packet transmission.
Server would receive any packet to port 4444 and ANY ip address.

Problem 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 points

Output is = abcde

Output is 5 characters read from the file "datapath". when the program starts a pipe is created and
another process is started.
Child process closes the write end of pipe while parent process closes the read end of the pipe. Parent
process reads from the file "datapath" and writes it onto the pipe, on the other hand child process reads
from the pipe and write it to console.

Problem 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 points

Output = 0123456789

SYS1 is the server which is bind to port 4444 and SYS2 is the client which is sending the message of
length 10 to SYS1. Server waits to receive the message after binding the port and receives the message
from the SYS2 using the socket. Stream socket type is used in this scenerio, which implies a TCP packet
transmission.
Server would receive any packet to port 4444 and ANY ip address.
Problem 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 points

Output is = Enter word :

This program asks for an input and save the input to the pipe unless a "q" character is found in the input
string. as soon as "q" is found the program discards the next characters of input string and reads from the
pipe and writes the contents to the console, in addition it reads from the file "datapath" and write it's
content on the console as well.
In this code it uses the ctermid argument to read the file name and opens the file "datapath" as passed to
the binary file.
Problem 9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 points
If the character associated with SIGINT is typed from the keyboard, then all processes that are in
the session that contains the foreground process group will receive this signal. Is this statement
true or false?

Whenever ctrl+c is pressed, a signal SIGINT is sent to the process. The default action of this signal
is to terminate the executing PROCESS. The processes that are in the session that contains the
foreground process group are unaltered as they have already completed their execution. Hence this
statement is false.

Problem 10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 points
In the context of CPU time spent relative to a single process, describe what wall clock (real time),
user time and system time is.

Real is wall clock time - time from start to finish of the call. This is all elapsed time including
time slices used by other processes and time the process spends blocked (for example if it is
waiting for I/O to complete).
User is the amount of CPU time spent in user-mode code (outside the kernel) within the
process. This is only actual CPU time used in executing the process. Other processes and time
the process spends blocked do not count towards this figure.
Sys is the amount of CPU time spent in the kernel within the process. This means executing
CPU time spent in system calls within the kernel, as opposed to library code, which is still
running in user-space. Like 'user', this is only CPU time used by the process. See below for a
brief description of kernel mode (also known as 'supervisor' mode) and the system call
mechanism.

Problem 11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 points
How could we use the special file /dev/zero to share information between two processes? How
would we create these processes and which function we would use to facilitate the information
share?

A program that needs a source of 0 bytes can mmap the file /dev/zero. Custom memory allocators often
map /dev/zero to obtain chunks of pre initialized memory.

A use case is described below:
The program opens the /dev/zero device and calls mmap, specifying a size of a long integer.
Once the region is mapped, we can close the device.
The process then creates a child.
Specifying MAP_SHARED in the call to mmap, writes to the memory-mapped region by one
process and seen by the other process.

S-ar putea să vă placă și