Pages

Wednesday, February 5, 2014

Andrew - Lab 2

3. Consider a transmission link:
36000m long and uses 1Gbps transmission speed. How long will it take to transmit a 10MB file along this link?
  83886080
__________ = 0.083886080 x 1000 = 83.886 milliseconds
1000000000

     3600
_________ = 0.0000120083 x 1000 = 0.012 milliseconds
299792458

83.886 + 0.012 = 83.898 milliseconds

2m long link with 10bps transmission rate. Assume that the propagation speed is equal to the speed of light.
83886080
________ = 8388608 x 1000 = 8388608000 milliseconds
      10

        2
_________ = 0.0000000066728 x 1000 = 0.0000066728 milliseconds
299792458

8388608000 0.0000066728 = 8388608000.0000066728 milliseconds

4. Pipes and Shared Memory:
Pipes can be used only between processes that have a common ancestor. Normally, a pipe is created by a process, that process calls fork, and the pipe is used between the parent and the child.
For Example: Creating an IPC channel from the parent to the child or vice versa, we call a function called fork. The fork depends on which direction of data flow we want. For a pipe from the parent to the child, the parent closes the read end of the pipe (fd[0]), and the child closes the write end (fd[1]).











Shared memory is the fastest form of IPC available. It is a type of IPC where the two processes share same memory chunk and use it for IPC. One process writes into that memory and other reads it. Unlike other forms of IPC such as pipes, where two processes go through a kernel to exchange informatiom. shared memory lets two or more processes share a region of memory.
For Example: The parent will be able to input the information into the shared memory which will then be output to the child from the shared memory instead of the kernel.


5. fwrite() and fread() Functions:
Example:
fread(info, strlen(info)+1, 1, fp); Reads data to the file
fwrite(info, strlen(info) +1, 1, fp); Writes data to the file
Where we set fp=fopen("the file", "info");

In other words, fwrite() function is the opposite of fread(). It writes to file associated with fp, num number of objects, each object size bytes long, from the buffer pointed to by buffer. It returns the number of objects written. This value will be less than num only if an output error as occurred. fread/fwrite returns the number of bytes actually read/written from/to the stream opened by fopen function. In case of failure, a lesser number of byes (then requested to read/write) is returned.
Credits to thegeekstuff.com and infohost.nmt.edu for info.

1 comment:

Note: Only a member of this blog may post a comment.