Question 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?
Answer:
Length
of transmission link = 36000 m
Speed of
transmission = 1Gbps
Propagation
speed of light = 3.0 x 10^8 m/s (which is equal to 299,792,458 metres per second).
Formula for
Propagation Delay (D) = Length / speed of light (C)
By plugging
in the value we get
D = 36000 / 299792458 we
will get approximately .00012seconds which is 0.12ms.
Formula for
transmission delay = M(bits)/ Rate (bits/sec) = M/R seconds
M = length
of message
R = transmission
speed
Rate(bits/sec)
= 1 gbps = 10^9 bits
M(bits):
10MB
By plugging
the values we get
T-delay = 10*2^20*8
/ 10^9 = approximately 84ms
Formula for Latency (L) = T-delay +
propagation delay (D)
L = .12 + 84 = 84.12ms
Question 3b.
For a 2m long link with
10bps transmission rate. Assume that the propagation speed is equal to the
speed of light.
Answer:
Length
of transmission link = 2m
Speed of
transmission = 10bps
Propagation
speed of light = 3.0 x 10^8 m/s (which is equal to 299,792,458 metres per second).
Formula for
Propagation Delay (D) = Length / speed of light (C)
By plugging
in the value we get
D = 2 / 299792458 we will
get approximately 6.67 * 10^6 ms.
Formula for
transmission delay = M(bits)/ Rate (bits/sec) = M/R seconds
M = length
of message
R = transmission
speed
By plugging
the values we get
T-delay = 10*2^20*8
/ 10 = approximately 8.4 * 10^9ms
Formula for Latency (L) = T-delay +
propagation delay (D)
L = .6.67 * 10^-6 +8.4 * 10^9 = 8.4 * 10^9 ms
Question 4:
PIPES:
A pipe is a serial
communication device (i.e., the data is read in the order in which it
was written). The data written to end is read back from the other end.The pipe is mainly used to communicate between two threads in a single process or between parent and child process. Pipes can only connect the related process. In shell, the symbol | can be used to create a pipe.
Pipes Functions: pipe()
Pipe functions are used for passing data between two programs and also allows to read and write the data.
#include<unistd.h>
int pipe(int file_descriptor[2]);
Ø
pipe()function is
passed with an array of file descriptors. It will fill the array with new file
descriptors and returns zero. On error, returns -1 and sets the error to
indicate the reason of failure.
Ø
The file descriptors
are connected in a way that is data written to file_ descriptor[1] can be read
back from the file_descriptor[0].
Popen() and Pclose() functions.
Popen();
FILE *Popen(const char *type , const char *open-mode);
(Note) On failure Popen() will returns a NULL pointer.
Pclose();
int
Pclose(FILE *stream_close);
(Note) By using Pclose(),
we can close the filestream associated with Popen().
Shared memory:
A process can allocate a shared memory
by using shmget() function.
#include<sys/shm.h>
int shmget(key_K key,size_K size,int shmflg);
int shmget(key_K key,size_K size,int shmflg);
Ø The first parameter is the integer key that specifies which
segment to create.
Ø
The second parameter
specifies the number of bytes in the segment.
Ø The third parameter is the flag values, which specifies the
options to shmget().
shmat():
shmat()
function is used to attached to the address space of a process.
void *shmat(int shmid, const void *shmaddr, 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.
Ø
The third parameter is the
flag value.
shmctl();
The shmctl()will
return the information about a shared memory segment and it can also be
modified.
int shmctl(int shmid, int cmd, struct shmid_ds *buf);
shmdt():
The shmdt function will detach the
shared memory from the current process.
shmdt(const void *shmaddr);
It takes the pointer to the address returned
by the shmget as the parameter. On success it returns 0,and -1 on
error.
QUESTION 5:
#include <stdio.h>
QUESTION 5:
#include <stdio.h>
#include <string.h>
int main()
{
int i, j, k;
FILE *fd, *fr;
char buff[100];
memset(buff, 0, sizeof(buff));
fd = fopen("text.c", "rw+");
if(fd == NULL)
{
printf("Error: fopen()");
return 0;
}
i = fread(buff, 1, 100, fd);
if(i != 100)
{
printf("Error: fread()");
return 0;
}
printf("File Content\n%s", buff);
fr = fopen("test.txt", "rw+");
if(fr == NULL)
{
printf("FR:Error fopen()");
return 0;
}
i = fwrite(buff, 1, 100, fr);
if(i != 100)
{
printf("fr:Error fwrite()");
return 0;
}
fclose(fd);
fclose(fr);
return 0;
}
good! you had the right ideas for the functions
ReplyDelete