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? Repeat this question for a 2m long link with
10bps transmission rate.
Assume that the propagation speed is equal to the speed of light.
A) :-
Length of transmission link = 2m
speed of transmission = 1Gbps = 109bits = 1000000000bits.
Propagation speed = 299 792 458 m/s
D = L / C
=> 36000 / 299792458 = 0.12 ms
Transmission delay = M /R
=> 10*2^20*8 / 10^9 = 85ms
L = T-delay + D
L = .12 + 85 = 85.12ms
B) :-
Length of transmission link = 36000m
speed of transmission = 10bps
Propagation speed = 299 792 458 m/s
D = L / C
=> 2/ 299792458 = 6.67 * 10^6 ms
Transmission delay = M /R
=> 10*2^20*8 / 10 = approximately 8.4 * 10^9ms
L = T-delay + D
=> .6.67 * 10^-6 +8.4 * 10^9 = 8.4 * 10^9 ms
Question 4:-
pipe - create an interprocess channel
SYNOPSIS
#include <unistd.h>
int pipe(int fildes[2]);
DESCRIPTION
The pipe() function shall create a pipe and place two file descriptors, one each into the arguments fildes[0] and fildes[1], that refer to the open file descriptions for the read and write ends of the pipe. Their integer values shall be the two lowest available at the time of the pipe() call. The O_NONBLOCK and FD_CLOEXEC flags shall be clear on both file descriptors. (The fcntl() function can be used to set both these flags.)
Data can be written to the file descriptor fildes[1] and read from the file descriptor fildes[0]. A read on the file descriptor fildes[0] shall access data written to the file descriptor fildes[1] on a first-in-first-out basis. It is unspecified whether fildes[0] is also open for writing and whether fildes[1] is also open for reading.
A process has the pipe open for reading (correspondingly writing) if it has a file descriptor open that refers to the read end, fildes[0] (write end, fildes[1]).
Upon successful completion, pipe() shall mark for update the st_atime, st_ctime, and st_mtime fields of the pipe.
RETURN VALUE
Upon successful completion, 0 shall be returned; otherwise, -1 shall be returned and errno set to indicate the error.
ERRORS
The pipe() function shall fail if:
- [EMFILE]
- More than {OPEN_MAX} minus two file descriptors are already in use by this process.
- [ENFILE]
- The number of simultaneously open files in the system would exceed a system-imposed limit.
source :- http://pubs.opengroup.org/onlinepubs/009696699/functions/pipe.html
CreatePipe creates the pipe, assigning the specified pipe size to the storage buffer. CreatePipe also creates handles that the process uses to read from and write to the buffer in subsequent calls to the ReadFile and WriteFile functions.
To read from the pipe, a process uses the read handle in a call to the ReadFile function. ReadFile returns when one of the following is true: a write operation completes on the write end of the pipe, the number of bytes requested has been read, or an error occurs.
When a process uses WriteFile to write to an anonymous pipe, the write operation is not completed until all bytes are written. If the pipe buffer is full before all bytes are written, WriteFile does not return until another process or thread uses ReadFile to make more buffer space available.
Anonymous pipes are implemented using a named pipe with a unique name. Therefore, you can often pass a handle to an anonymous pipe to a function that requires a handle to a named pipe.
If CreatePipe fails, the contents of the output parameters are indeterminate. No assumptions should be made about their contents in this event.
To free resources used by a pipe, the application should always close handles when they are no longer needed, which is accomplished either by calling the CloseHandle function or when the process associated with the instance handles ends. Note that an instance of a pipe may have more than one handle associated with it. An instance of a pipe is always deleted when the last handle to the instance of the named pipe is closed.
source :- http://msdn.microsoft.com/en-us/library/windows/desktop/aa365152%28v=vs.85%29.aspx
Question 5:-
#include <stdio.h> int main() { int row, column; FILE *my_stream; int close_error; char my_filename[] = "my_numbers.dat"; size_t object_size = sizeof(int); size_t object_count = 25; size_t op_return; int my_array[5][5] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50 }; printf ("Initial values of array:\n"); for (row = 0; row <= 4; row++) { for (column = 0; column <=4; column++) { printf ("%d ", my_array[row][column]); } printf ("\n"); } my_stream = fopen (my_filename, "w"); op_return = fwrite (&my_array, object_size, object_count, my_stream); if (op_return != object_count) { printf ("Error writing data to file.\n"); } else { printf ("Successfully wrote data to file.\n"); } /* Close stream; skip error-checking for brevity of example */ fclose (my_stream); printf ("Zeroing array...\n"); for (row = 0; row <= 4; row++) { for (column = 0; column <=4; column++) { my_array[row][column] = 0; printf ("%d ", my_array[row][column]); } printf ("\n"); } printf ("Now reading data back in...\n"); my_stream = fopen (my_filename, "r"); op_return = fread (&my_array, object_size, object_count, my_stream); if (op_return != object_count) { printf ("Error reading data from file.\n"); } else { printf ("Successfully read data from file.\n"); } for (row = 0; row <= 4; row++) { for (column = 0; column <=4; column++) { printf ("%d ", my_array[row][column]); } printf ("\n"); } /* Close stream; skip error-checking for brevity of example */ fclose (my_stream); return 0; }If all goes well, the code example above will produce the following output:
Initial values of array: 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 Successfully wrote data to file. Zeroing array... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Now reading data back in... Successfully read data from file. 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50
source :- http://crasseux.com/books/ctutorial/Block-input-and-output.html
Good work with the functions and the program
ReplyDelete