Upload
t-s-pradeep-kumar
View
2.478
Download
2
Embed Size (px)
Citation preview
INTER PROCESS COMMUNICATION
SEMAPHORE INFO
seminfo Value
semmni (maximum number of semaphore arrays)
128
semmns (maximum number of semaphores in the system
32000
semmsl (number of semaphores per array) 250
semvmx (maximum value of semaphores 32767
SHARED MEMORY INFO
shminfo Value
shmmni (maximum no of shared memory segment)
4096
shmmax (maximum size of SHM segment in bytes)
33,554,432
shmmin (minimum size of SHM segment in bytes)
1
shmseg (permitted no of segments/processes) 4096
MESSAGE QUEUE INFO
msginfo Valuemsgmni (maximum number of message queue) 16
msgmax (maximum size of a message in bytes) 8192
msgmnb (standarad value for the maximum size of a message queue in bytes)
16384
PIPES & NAMED PIPES
Pipes are the classical method of interprocess communication. For example
ls –l | more
The symbol | indicates a pipe and the shell in the above example runs the processes ls and more which are linked with a pipe. ls writes data to the pipe and more reads it.
Named pipes otherwise called as the FIFO (First in First Out) is the other variant of pipe.
PIPES & NAMED PIPES
# mkfifo pathname Example
# mkfifo hello # ls –l hello prw-r- -r- – 1 temp users 0 Aug 28
10.45 hello |
PIPES & NAMED PIPES
there are many similarities between the pipes and the FIFO, but the inode specification for the both are more or less the same.
following is the inode specification for the pipe
PIPES & NAMED PIPES
struct pipe_inode_info { wait_queue_head_t wait; //wait queue char * base; //address of the FIFO buffer unsigned int readers; //no of processes reading at this moment unsigned int writers; //no of processes writing at this moment unsigned int waiting_readers; //no of blocked process reading
at this moment unsigned int waiting_writers; //no of blocked processes writing
at this moment unsigned int r_counter; //no of read processes that have opened unsigned int w_counter; //no of write processes that have
opened };
OPEN A FIFO
Blocking Non Blocking
For reading No writing processes
Block Open FIFO
Writing processes Open FIFO Open FIFO
For Writing No reading processes
Block Error ENXIO
Reading Processes Open FIFO Open FIFO
For reading and Writing
Open FIFO Open FIFO
PTRACE
Ptrace is a system call provided in unix for one process to take control of another process to debug errors or bugs in the system
The process under control can be run step by step and its memory can be read and modified. int sys_ptrace(long request, long pid, long addr, long
data); the function processes various request defined in the
parameter request and pid indicates the process id of the process to be controlled.
Using the request PTRACE_TRACEME, a process can specify that its parent process controls iut via ptrace().
SOCKETS
Socket programming interfaces provides communication via a network as well as locally on a single computer. Example is INET daemon which waits for incoming network service requests and then call the appropriate service program using the socket file descriptor as standard input and output.
Implementation of Unix domain sockets Represented by a kernel data structure socket Socket specific functions like Socket(), setsockout() The functions are implemented with a single system
call socketcall which calls all the necessary functions by reference to the first parameter. The file operation read(), write(), poll(), ioctl(), lseek(), close() are called directly
SOCKETS
Operations of Unix domain sockets long sys_socket(int family, int type, int protocol);//
creates a socket file descriptor long sys_connect(int fd, struct sockaddr * uservaddr, int
addrlen); //bind the socket to the unix domain address with specified length
long sys_listen(int fd, int backlog);//checks whether any connections are being accepted at the server address.
long sys_accept(int fd, struct sockaddr *upeer_sockaddr, int *upeer_addrlen));//server informs the kernel that the connections are being accepted from now on
long sys_getsockname(int fd, struct sockaddr *usockaddr, int *usockaddr_len); //the address bound to the socket is returned.
SOCKETS
long sys_shutdown(int fd, int how); //to shutdown but status to be given that whether the sending and receiving still allowed
sending and receiving from the sockets Messages can be sent either as a datagram or stream of
bytes long sys_send(int fd, void *buff, int len, unsigned
flags); long sys_sendmsg(int fd, struct msghdr *msg,
unsigned int flags); long sys_recv(int fd, void *buff, int len, unsigned
flags); long sys_recvmsg(int fd, struct msghdr *msg,
unsigned int flags)