Wednesday,
February 5, 2014
Q #3
(I)
D = 36000/299792458
= 0.00012 ms
M= 10MB
=83886080 bits
R=1Gbps = 1000000000 bps
L= D + M/R
= (83886080/1000000000)+0.00012
=0.084+0.00012
=0.08412 ms
(II) This is 2 m long and10 bps speed
D= 2/299792458
=0.00000667 ms
M=83886080 bits
R=10 bps
L=(8388608/10)+0.00000667
=8388608+0.00000667
=8388608
Q#4
Pipes: This is implemented in file system. Pipes are basically files with only two file offsets: one for reading and othe is writing. writing to a file and reading from a pipe is strictly in a queue manner, so pipes are called FIFOs. Pipe can write multiprocess, but read only one process.
There are two types of pipes: anonymous pipes and named pipes.
There are several functions to implement a pipe:
1. Pipe created by the server this is done using the Createnamedpipe function(). the pipe name is a string with format : \\.\pipe\[pathname]pipename. the "." stands for the local machine name.
2. After created pipe,the creating process(sever) must wait for clients to connect to the pipe.
the Connectnamedpipe() function connects to the named pipe by calling createfile(). after sucessfully connecting,the server can read or write into the pipe.
3. Readfile() allows the clients to read from the pipe. file= filer ("filename")
4.Writefile() allows the clients to write to the pipe. file=filew("filename")
.
5. After a pipe has been created at the server side, a client process can connect to the pipe by calling the createfile() function.
Shared Memory:
Shared memory can multiprocess for Read and Write. Two or several processes can map a segment or their virtual space into an identical segment of physical memory. shared memory is the most effecient way of IPC,but it may require synchronization.
System calls:
1. shmget(key,size,flags);
int sid;
long key;
int size;
int flags;
this function creates a shared memory segment.
2. shmdt(sid,addr,flags);
char *p;
void addr;
this function attaches the shared memory segment,that is, it gets the shared memory segment address.
3. shmctl(sid,cmd,sbuf);
int cmd;
this function allows you to control the share memory segment.
Question 5.
Fread()
The fread function is a subroutine that copies the number of data specified by the numberofitems parameter from the input stream into an array beginning at the location pointed to by the pointer parameter. each data item has the form *pointer. The fread subroutine stops copying bytes it an end of file (eof) or error condition is encountered while reading from the input specified by the numberofitems parameter have been copied. This subroutine leaves the file pointer of the stream parameter,if defined, pointing to the byte following the last byte read. the fread subroutine does not change the contents of the stream parameter.
example:
#include <studio.h>
#include<string.h>
int main()
{
File *fs;
char t[]=" This is york college";
char buffer[20];
fs=fopen(file.txt", "j+');
fseek(fs, set,0);
fread(buffer, length(j)+1, 1,f);
printf("%s\n",buffer);
fclose(fs);
return 0;
}
Fwrite()
fwrite subroutine writes items from the array pointed to by the pointer parameter to the stream pointed to by the stream parameter. each item's size is specified by the size parameter. the fwrite subroutine writes the number of items specified by the numberofitems parameter. the file position indicator for the stream is advanced by the number of bytes successfully written. if an error occurs, the resulting value of the file position indicator for the stream is intermediate. the fwrite subroutine appends items to the output from the array pointed to by the pointer parameter. the fwrite subroutine appends as many items as specified in the numberofitems parameter.
examples:
#include <studio.h>
#include<string.h>
int main()
{
FILE *fp;
#include <studio.h>
#include<string.h>
int main()
{
FILE *fp;
fp=fopen("c:\\test.bin",
"wb");
char x[10]="ABCDEFGHIJ";
fwrite(x, sizeof(x[0]),
sizeof(x)/sizeof(x[0]), fp);
return 0;
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.