Pages

Wednesday, February 5, 2014

Lab Assignment 2

3.)
  A)   length = 36,000
      Speed of signals = 10^9

Transmission Delay = M(bits)/R(bps)
10 MB = 83886080 bits / 1GB = 10^9 = 0.083 m/s



 Propagation Delay = D(seconds) so, formula for D = length / speed of signals.   36,000/10^9 =0.000036 m/s


Latency = M(bits)/R(bps)+D

10 MB = 83886080 bits / 1GB = 10^9 = 0.083 m/s , therefore 0.083+0.000036 = 0.084 m/s


B)
Transmission Delay = 10^6/10 =100000 m/s

Propagation Delay
 Length=                  2
                         ________ =  0.2 m/s

Speed of signal=     10 bps

Latency = 100000+0.2 = 100000.2 m/s

4.) IPC is a set of methods for the exchange of data among multiple threads.
the pipe() function provides a means of passing data between two programs and also allows to read and write the data.
#include<unistd.h>
int pipe(int file_descriptor[2]);
Return 0; // if an error Return -1;

Pipe Processing-
The process of passing data between two programs can be done with the help of popen() and pclose() functions.
#include<stdio.h>
FILE *popen(const char *command ,  
const char *open-mode);
int pclose(FILE *stream_to_close);
The popen function allows a program to declare another program as a new process and either writes the data to it or to read from it. To perform bi-directional communication you have to use two pipes.

By using pclose(), we can close the filestream associated with popen() after the process started by it has been finished. The pclose() will return the exit code of the process, which is to be closed.
Shared Memory Segment is a method of IPC that where two or more processes share a single chunk of memory to communicate.
#include<sys/shm.h>
void *shmat(int shm_id,
const void *shm_addr,int shmflg);

The first parameter is the shm_id,
identifier returned by the shmget.
The second parameter is the address at which the segment is to be attached to the current process. This will always be NULL pointer so that system can choose the address at which the memory is available.

The third parameter is the flag value. There are two possible flag values they are:
1.) SHM_RND-controls the address at which the segment is attached.
2.) SHM_RDONLY-makes the attachment read-only.
 


Source - http://developeriq.in/articles/2012/may/30/interprocess-communicationipc-programs-in-c-in-ubu/



5.) #include <stdio.h>

fread(void *buffer, size_t size, size_t num,FILE *fp);
{
.
.
.
return num;
}

 fwrite(void *buffer, size_t size, size_t num, FILE *fp);
{
.
.
.
 return num;
}

fread- reads a block memory or file and Fwrtites does the complete opposite of Fread.Fwrite creates a block into the file.

fp(stands for file pointer) is where you should write your file. Num is return because it is how many elements that were read and written. In Fread if
the number returned is  zero its either 1: no files has been read.
                               2: an error occured.

In Fwrite if the number of values written is less than num then an there is an error.

1 comment:

  1. write a short program with fread and fwrite. this will be prety much like the programs for reading and writing in files in CS 172 but instead of fin >> and fout << we use fread and fwrite.

    ReplyDelete

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