Pages

Wednesday, February 5, 2014

Lab 2

Question 3

Transmission delay:
M / R = 10MB / 1Gps
     = ( 10 * 1048576 ) 8 / 1000000000
     = 0.83886080 seconds
     = 83.886 ms

Propagation delay:
D = 36000 / c
           = 36000 / 299792458
           = 0.0001200830743 seconds 
           = 0.120083074 ms


L = ( M / R ) + D
   = 83.886 + 0.120083074
   = 84. 00608307 ms
-----------------------------------------------
Transmission delay:
M / R = 10MB / 10bps
     = ( 10 * 1048576 ) 8 / 10
     = 8388608 seconds
     = 8.389x10^9 ms

Propagation delay:
D = 2 / c
           = 2 / 299792458
           =  0.0000000066728 seconds 
           =  0.0000066728 ms or 6.6728x10^-6


L = ( M / R ) + D
   = 8.389x10^9 + 6.6728x10^-6

   =  8.389x10^9 ms

Question 4 



Pipe uses an access point which is a file in the file system. A method for writing and reading between two given inter-connected functions or two set of functions called message pipe. Writing and reading to a pipe is likely using a C command which are fwrite wit a file name that writes into a named file, fread with a file name that reads into a named file. The fwrite function can write to a pipe at the back pointer address using *pback. The fread function can read from a pipe at the front pointer address using *pfront. The message pipe at the pipe function memory buffer for writing and reading as FIFO. The limitation in a pipe may have a variable number bytes per message among initial and final pointers.



Functions implementing Pipe:

- using pipefunccreate( ) is a function to initialize a pipe function.

- using open ( )is for opening function to implement it use from the starting of its allocated buffer. It uses with option and condition defined at the time of opening

- using connect( ) is for connecting a thread or function filling in bytes into the pipe to the thread or function eliminating bytes from the pipe

- using write( ) is a function for writing or inserting into the pipe from the bottom of the empty memory space of its allocated buffer

- using read( ) is a function for reading or deleting from the pipe from the bottom of the unread memory spaces in the buffer loaded after writing into the pipe
-using close( ) is for closing the function to set up its purpose from the beginning of its buffer allotted only after opening it again 

Shared memory is an efficient means of passing data between programs. one program will create a memory portion which other processes can access once it is permitted. One process writes into the memory and other read it. Shared memory differs from pipes since multiple process can read and write however user need to provide mutual exclusion for read and write. pipes do almost the same except that only one process can read.
shared memory gives more control over buffering and resources. its the person who decides how much memory to allocate and how to use it. in other words, shared memory is more manual than pipes.

Basic functions for shared memory include:
shmget()  way to identify a thread
shmat()  a process gets address-ability to the shared memory
shmdt() a process detaches shared memory
shmctl() a thread removes a shared memory ID

Question 5

The fread function returns the number of characters successfully read, which may be less than nmemb if a read error or end of file is. If size or nmemb is zero, fread returns zero and the contents of the array and the state of the stream remain unchanged.


#include <stdio.h>

int main()

   FILE *fichero;
   char name[11] = "datos5.dat";
   unsigned int money[10] = \{ 23, 12, 45, 345, 512, 345, 654, 287, 567, 124 \};
   unsigned int read[10], i;

   fichero = fopen( name, "w+" );
   printf( "Fichero: %s -> ", name );
   if( fichero )
      printf( "created (Open)\\n" );
   else

      printf( "Error (NOT OPEN )\\n" );
      return 1;


   printf( "Writing amounts:\\n\\n" );

   for( i=0; i<10; i++ )
     printf( "%d\\t", money[i] );

   fwrite( money, sizeof(unsigned int), 10, fichero );

   printf( "\\nreading data from fichero \\"%s\\":\\n",  name);
   rewind( fichero );
   fread( read, sizeof(unsigned int), 10, fichero );

   for( i=0; i<10; i++ )
     printf( "%d\\t", read[i] );

   if( !fclose(fichero) )
      printf( "\\nFichero closed\\n" );
   else

      printf( "\\nError: fichero NOT CLOSED\\n" );
      return 1;


   return 0;

}

Collaborator: Chessa Flores

No comments:

Post a Comment

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