OS-IPC_QB_Answers

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

With the help of a neat schematic, describe the client and server model.

(Picture is in seperate file)

One pipe buffer consists of ........ page frame(s)

1

State the three limitations of a pipe.

1) there is no way to open an already existing pipe. 2) This makes it impossible for two arbitrary processes to share the same pipe, unless the pipe was created by a common ancestor process. 3) server and client processes thus cannot easily share a pipe.

Describe the operations performed by the function popen().

1. Creates a new pipe by using the pipe( ) system call. 2. Forks a new process, which in turn executes the following operations: a. If type is r, it duplicates the file descriptor associated with the pipe's write channel as file descriptor 1 (standard output); otherwise, if type is w, it duplicates the file descriptor associated with the pipe's read channel as file descriptor 0 (standard input). b. Closes the file descriptors returned by pipe( ). c. Invokes the execve( ) system call to execute the program specified by filename. 3. If type is r, it closes the file descriptor associated with the pipe's write channel; otherwise, if type is w, it closes the file descriptor associated with the pipe's read channel. 4. Returns the address of the FILE file pointer that refers to whichever file descriptor for the pipe is still open.

Distinguish between kernel semaphore and IPC semaphore.

1. IPC semaphores is a set of one or more semaphore values, not just a single value like a kernel semaphore. 2. this means that the same IPC resource can protect several independent shared data structures.

. List out the steps involved in establishing a socket on the client side.

1. Socket Creation Create a socket with the socket() system call 2. Connect Connect the socket to the address of the server using the connect() system call 3. Send/Recv Send and receive data. There are a number of ways to do this, but the simplest is to use the read() and write() system calls.

List out the steps involved in establishing a socket on the server side.

1. Socket Creation Create a socket with the socket() system call 2. Set Socket option Set socket option using setsockopt() system call 3. Bind Bind the socket to an address using the bind() system call. For a server socket on the Internet, an address consists of a port number on the host machine. 4. Listen Listen for connections with the listen() system call 5. Accept Accept a connection with the accept() system call. This call typically blocks until a client connects with the server. 6. Send/Recv Send and receive data

. Describe the two functions used by the processes to send and receive messages via the IPC message queue resource.

1. To send a message, a process invokes the msgsnd( ) function 2. To retrieve a message, a process invokes the msgrcv( ) function

Each pipe makes use of ......... pipe buffers which greatly enhances the performance of User Mode applications that write large chunks of data in a pipe.

16

Explain what is meant by a socket.

A Socket is an end point of communication between two systems on a network.

Explain what is meant by a pipe.

A pipe is a one way flow of data between processes: all data written by a process to the pipe is routed by the kernel to another process, which can thus read it.

Explain the operations performed by the following functions : a) mknod() b) mkfifo()

A process creates a FIFO by issuing a mknod( ) system call passing to it as parameters the pathname of the new FIFO and the value S_IFIFO (0x10000) logically ORed with the permission bit mask of the new file. POSIX introduces a function named mkfifo( ) specifically to create a FIFO.

Explain the following : a) Address Domain b) Address format c) Port Number d) Socket types

ADDRESS DOMAIN : • There are two widely used address domains : UNIX domain INTERNET domain • The unix domain, in which two processes which share a common file system communicate, and • The Internet domain, in which two processes running on any two hosts on the Internet communicate. ADDRESS FORMAT : • Each of these address domains has its own address format. • The address of a socket in the Unix domain is a character string which is basically an entry in the file system. • The address of a socket in the Internet domain consists of the Internet address of the host machine (every computer on the Internet has a unique 32 bit address, often referred to as its IP address). PORT NUMBER : • In addition, each socket needs a port number on that host. • Port numbers are 16 bit unsigned integers. • The lower numbers are reserved in Unix for standard services. For example, the port number for the FTP server is 21. • It is important that standard services be at the same port on all computers so that clients will know their addresses. However, port numbers above 2000 up to to 65535 are generally available. SOCKET TYPES : • There are two widely used socket types, stream sockets, and datagram sockets. • Stream sockets treat communications as a continuous stream of characters, while datagram sockets have to read entire messages at once. • Each uses its own communications protocol. • Stream sockets use TCP (Transmission Control Protocol), which is a reliable, stream oriented protocol (connection-oriented) • Datagram sockets use UDP (Unix Datagram Protocol), which is unreliable and message oriented. (connection less) • In our example , we use sockets in the Internet domain using the TCP protocol.

. What is an IP address? Distinguish between IPv4 and IPv6 addresses.

An Internet Protocol address (IP address) is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. • Version 4 of the Internet Protocol (IPv4) defines an IP address as a 32-bit number. • However, because of the growth of the Internet and the depletion of available IPv4 addresses, a new version of IP (IPv6), using 128 bits for the IP address, was developed in 1995, and standardized as RFC 2460 in 1998

Explain the method used to compute IPC resource Identifier by providing the expression used and indicating clearly all the parameters used in the expression to compute the IPC identifier.

Each IPC identifier is computed by combining a slot usage sequence number relative to the resource type, an arbitrary slot index for the allocated resource, and an arbitrary value chosen in the kernel that is greater than the maximum number of allocatable resources. S is slot usage sequence number M is upper bound on the number of allocatable resources I is slot index where 0<=i<M: IPC identifier = s x M + i

. Explain IPC Semaphores.

IPC semaphores are counters used to provide controlled access to shared data structures for multiple processes.

. Explain clearly how swapping out pages of IPC shared memory regions are handled by the kernel.

In order to reclaim a page of an IPC shared memory region, the kernel must write it into a swap area. ~ Because an IPC shared memory region is persistent that is, its pages must be preserved even when the segment is not attached to any process the kernel cannot simply discard these pages even when they are no longer used by any process. These pages are handled through the demand paging mechanism. The pages added to a process by shmat( ) are dummy pages; the function adds a new memory region into a process's address space, but it doesn't modify the process's Page Tables.

Six basic mechanisms offered by linux systems to allow Inter Process Communication

Pipes FIFOs Semaphores Message Queues Shared Memory Sockets

. What are well-known ports or default TCP port numbers?

Port numbers 0 to 1024 are reserved for privileged services and designated as well-known ports.

. Explain what is meant by IPC message queue.

Processes can communicate with one another by means of IPC messages. Each message generated by a process is sent to an IPC message queue, where it stays until another process reads it.

List the three kinds of System V IPC resources.

Semaphore, 2message queue, 3shared memory region

Describe socket programming.

Socket programming is a way of connecting two nodes on a network to communicate with each other.

Discuss TCP/IP Protocol suite

TCP/IP specifies how data is exchanged over the internet by providing end-to-end communications that identify how it should be broken into packets, addressed, transmitted, routed and received at the destination.

. What are primitive semaphores?

The counter inside IPC semaphore are referred to as a primitive semaphores.

. Describe the IPC shared memory resource.

The most useful IPC mechanism is shared memory , which allows two or more processes to access some common data structures by placing them in an IPC shared memory region

What are per-process list and per-semaphore list? Why are they required in semaphore operations?

The per-process list includes all sem_undo data structures corresponding to IPC semaphores on which the process has performed undoable operations. The per-semaphore list includes all sem_undo data structures corresponding to the processes that performed undoable operations on the semaphore

Describe all the actions essentially performed by the command shell when the command statement ls | more is interpreted and executed after invoking the pipe command. Also clearly indicate the actions performed by the two child processes created.

The standard output of the first process, which executes the ls program, is redirected to the pipe; the second process, which executes the more program, reads its input from the pipe.

. Explain the relation between primitive and IPC semaphore

There are bounds both on the number of IPC semaphore resources (by default, 128) and on the number of primitive semaphores inside a single IPC semaphore resource (by default, 250).

Describe the fail-safe mechanism used by System V IPC semaphores for situations in which a process dies without being able to undo the operations that it previously issued on a semaphore.

Typical steps performed by a process wishing to access one or more resources protected by an IPC semaphore: Invokes the semget( ) wrapper function to get the IPC semaphore identifier, specifying as the parameter the IPC key of the IPC semaphore that protects the shared resources. If the process wants to create a new IPC semaphore, it also specifies the IPC_CREATE or IPC_PRIVATE flag and the number of primitive semaphores required. Invokes the semop( ) wrapper function to test and decrease all primitive semaphore values involved. If all the tests succeed, the decrements are performed, the function terminates, and the process is allowed to access the protected resources. If some semaphores are in use, the process is usually suspended until some other process releases the resources.

Explain what is meant by named pipe or FIFO.

Unix systems introduce a special file type called a named pipe or FIFO (which stands for "first in, first out;" the first byte written into the special file is also the first byte that is read).

Inter Process Communication (IPC)

User Mode processes can synchonize thier ations and exchange data

Explain the following functions : a) pipe() b) execve() c) dup2() d) popen() e) pclose() f) pipe_read() g) pipe_write()

a) A process creates a new pipe by means of the pipe( ) system call, which returns a pair of file descriptors. b) execve ( ) to execute program c) ex.: dup2(4,1) to copy file descriptor 4 to file descriptor 1. d) popen() to create a pipe e) pclose( ) function (which receives the file pointer returned by popen( ) as its parameter) simply invokes the wait4( ) system call and waits for the termination of the process created by popen( ). f)The pipe_read( ) function is quite involved, because the POSIX standard specifies several requirements for the pipe's read operations. g) The kernel satisfies this request by invoking the write method of the proper file object; the corresponding entry in the write_pipe_fops table points to the pipe_write( ) function.

Explain the purpose of the following : a) IPC key b) IPC Resource identifier

a) A process may require several IPC resources of the same type, each new source is identified by a 32-bit IPC key. b) for accessing the resources.

Explain the following : a) Pipes b) FIFOs c) Semaphores d) Message Queues e) Shared Memory f) Sockets

a) Best suited to implement producer/consumer interactions among processes. Some processes fill the pipe with data, while others extract data from the pipe. b) (which stands for "first in, first out;" the first byte written into the special file is also the first byte that is read). Each FIFO is much like a pipe: rather than owning disk blocks in the filesystems, an opened FIFO is associated with a kernel buffer that temporarily stores the data exchanged by two or more processes. c) IPC semaphores are counters used to provide controlled access to shared data structures for multiple processes. d) Processes can communicate with one another by means of IPC messages. Each message generated by a process is sent to an IPC message queue, where it stays until another process reads it. e) The most useful IPC mechanism is shared memory , which allows two or more processes to access some common data structures by placing them in an IPC shared memory region. ❖ Each process that wants to access the data structures included in an IPC shared memory region must add to its address space a new memory region, which maps the page frames associated with the IPC shared memory region. f) Allow processes on different computers to exchange data through a network. Sockets can also be used as a communication tool for processes located on the same host computer.

Describe the following functions by providing the complete syntax of the function and parameters required

a) Socket socket creation int sockfd =socket(domain, type, protocol) sockfd: socket descriptor, an integer (like a file-handle) domain: integer, communication domain e.g., AF_INET (IPv4 protocol) , AF_INET6 (IPv6 protocol) type: communication type SOCK_STREAM: TCP(reliable, connection oriented) SOCK_DGRAM: UDP(unreliable, connectionless) protocol: Protocol value for Internet Protocol(IP), which is 0. This is the same number which appears on protocol field in the IP header of a packet. Example : server_fd= socket(AF_INET, SOCK_STREAM,0) b) setsockopt . Set Socket option int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) c) bind Bind the socket to an address using the bind() system call. For a server socket on the Internet, an address consists of a port number on the host machine. int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) d) listen Listen for connections int listen(int sockfd, int backlog); e) accept Accept a connection with the accept() system call. This call typically blocks until a client connects with the server. int new_socket= accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) f) connect Connect the socket to the address of the server int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen g) read is used to read the buffer data read(sockfd, recvBuff, sizeof(recvBuff)-1) h) write is used to send the data. write(sockfd, sendBuff, sizeof(sendBuff)-1) i) send send data send(socket_desc , sendBuff , strlen(sendBuff) , 0) j) recv receive data recv(socket_desc , recvBuff , strlen(recvBuff),0)

Explain the purpose of the following functions : a) shmget() b) shmat() c) shmdt()

a) shmget( ) function is invoked to get the IPC identifier of a shared memory region, optionally creating it if it does not already exist. b) The shmat( ) function is invoked to "attach" an IPC shared memory region to a process. It receives as its parameter the identifier of the IPC shared memory resource and tries to add a shared memory region to the address space of the calling process c) The shmdt( ) function is invoked to "detach" an IPC shared memory region specified by its IPC identifier that is, to remove the corresponding memory region from the process's address space.

. Explain what is meant by undoable semaphore operations.

by declaring them undoable, the process lets the kernel return the semaphores to a consistent state and allow other processes to proceed

Number of IPC semaphore resources that can be used by default is .... a) 32 b) 64 c) 128 d) 256

c) 128

. Number of primitive semaphores available inside a single IPC semaphore resource by default is ..... a) 30 b) 60 d) 120 d) 250

d) 250

Describe the operations performed by the following library functions for POSIX message queues : a) mq_open() b) mq_close() c) mq_unlink() d) mq_send() d) mq_timedsend() e) mq_receive() f) mq_timedreceive()

mq_open( ) Open (optionally creating) a POSIX message queue mq_close( ) Close a POSIX message queue (without destroying it) mq_unlink( ) Destroy a POSIX message queue mq_send( ) , mq_send( ) Send a message to a POSIX message queue; mq_timedsend( ) defines a time limit for the operation mq_receive( ) Fetch a message from a POSIX message queue; mq_timedreceive( ) defines a time limit for the operation

Describe pipefs special filesystem. Indicate where this is located.

pipefs special filesystem: A pipe is implemented as a set of VFS objects, which have no corresponding disk images. In Linux, these VFS objects are organized into the pipefs special filesystem toexpedite their handling. The mounted filesystem object that represents the root directory of pipefs is stored in the pipe_mnt variable.

. Explain the purpose of the following functions : a) semget() b) msgget() c) shmget()

semget() to create semaphore IPC resource msgget() to create message queue IPC resource shmget() to create shared memory region IPC region

. State the purpose of select() command. Provide the complete syntax of the command clearly specifying the parameters required

• A better way to handle multiple clients is by using select() linux command. • Select command allows to monitor multiple file descriptors, waiting until one of the file descriptors become active. • For example, if there is some data to be read on one of the sockets select will provide that information. • Select works like an interrupt handler, which gets activated as soon as any file descriptor sends any data.

. Write the specific functions performed by TCP and IP protocols in the internet protocol suite.

• TCP defines how applications can create channels of communication across a network. • It also manages how a message is assembled into smaller packets before they are then transmitted over the internet and reassembled in the right order at the destination address. • IP defines how to address and route each packet to make sure it reaches the right destination. • Each gateway computer on the network checks this IP address to determine where to forward the message.

Discuss the following functions clearly explaining the parameters required by each of these functions. a) msgsnd() b) msgrcv() msgsnd() passes the following as parameters:

▪ The IPC identifier of the destination message queue ▪ The size of the message text ▪ The address of a User Mode buffer that contains the message type immediately followed by the message text. msgrcv() passes to it: ▪ The IPC identifier of the IPC message queue resource ▪ The pointer to a User Mode buffer to which the message type and message text should be copied ▪ The size of this buffer ▪ A value t that specifies what message should be retrieved ▪ If the value t is 0, the first message in the queue is returned. ▪ If t is positive, the first message in the queue with its type equal to t is returned. ▪ Finally, if t is negative, the function returns the first message whose message type is the lowest value less than or equal to the absolute value of t.

Distinguish between Pipes & FIFOs.

➢ FIFO inodes appear on the system directory tree rather than on the pipefs special filesystem. ➢ FIFOs are a bidirectional communication channel; that is, it is possible to open a FIFO in read/write mode.


Kaugnay na mga set ng pag-aaral

marketing test chapter 12, 13, 14, 15, 16

View Set

Unit 1: Early Hominids and the Beginnings of Humans

View Set

EAQ Week 4 Principles of Venipuncture

View Set

ENTR 3012 Intrapreneurship Test 1 (Cabral)

View Set

Possible Multiple Choice Question

View Set