Pages

Wednesday, February 5, 2014

Lab #2

3) Consider a transmission link that is 36000m long and uses 1Gbps transmission speed. How long will it take to transmit a 10MB file along this link? Assume that the propagation speed is equal to the speed of light

 Latency = Transmission delay + Propagation delay
               = (M/R) + D

Transmission Delay: M / R = 10MB / 1Gpbs
                                             =  (10 * 1048576) * 8 / 1000000000
                                             = 0.083886080s
                                             = 83.8861ms

Propagation Delay: D
                                = 3600 / c
                                =  3600 / 299792458
                                = 0.0000120083s
                                = 0.0120083ms 

Latency: (M / R) + D
               = 83.8861 + 0.0120083
               = 83.8981083ms

Repeat this question for a 2m long link with 10bps transmission rate. Assume that the propagation speed is equal to the speed of light.

 Latency = Transmission delay + Propagation delay
               = (M/R) + D

Transmission Delay: M / R = 10MB / 1bps
                                             =  (10 * 1048576) * 8 / 10
                                             = 8388608s
                                             = 8388608000ms

Propagation Delay: D
                                = 2 / c
                                =  2 / 299792458
                                = 0.0000000066728s
                                = 0.0000066728ms

Latency: (M / R) + D
               = 8388608000 + 0.0000066728
               = 8388608000ms
               = 8.388608ms + 10^9

4) We will start working on a group project that implements "Interprocess communication using pipes". Pipes is one of the ways to implement IPC. Write a blog that explains the functions needed to implement IPC using pipes and also those needed for communication using shared memory.

Functions that are required to implement IPC:
1. popen() : allows a program to invoke another program as a new process and either pass / receive
                   data to / from it.

2. pclose() : used to close the file stream created with popen()
3. fread() : used to read data from the file opened by the popen()
4. fwrite() : used to write data to the file



Functions needed for communication using shared memory:
1.  shmget() : used to access the shared memory
2. shmctl(): provides a variety of shared memory control operations that is specified by cmd
3. shmat(): attaches the shared memory segment
4. shmdt(): deattaches the shared memory segment

5) fread and fwrite are C functions that can read bytes (instead of lines, or strings, char etc) from a file. Describe these functions and also write short programs that demonstrate them.



fread() : used to read data from the file opened
fwrite() : used to write data to the file

Function example:

#include <stdio.h>
#include <string.h>

int main()
{
   FILE *fp;
   char c[] = "If you can see this, it worked.";
   char buffer[100];

   /* Opening the already created test file */
   fp = fopen("Testfile.txt", "w+");

   /* Writing "
If you can see this, it worked" to the file */
   fwrite(c, strlen(c) + 1, 1, fp);

   /* Reading what we wrote in the file */
   fread(buffer, strlen(c)+1, 1, fp);
   fclose(fp);
  
   return(0);
}


No comments:

Post a Comment

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