Inter process communication


Published on

Published in: Education
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Inter process communication

  1. 1. Inter process communication<br />
  2. 2. Semaphore info<br />
  3. 3. Shared memory info<br />
  4. 4. Message queue info<br />
  5. 5. Pipes & named pipes<br />Pipes are the classical method of interprocess communication.<br />For example<br />ls –l | more<br />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.<br />Named pipes otherwise called as the FIFO (First in First Out) is the other variant of pipe.<br />
  6. 6. Pipes & named pipes<br /># mkfifo pathname<br />Example<br /># mkfifo hello<br /># ls –l hello<br />prw-r- -r- – 1 temp users 0 Aug 28 10.45 hello |<br />
  7. 7. Pipes & named pipes<br />there are many similarities between the pipes and the FIFO, but the inode specification for the both are more or less the same.<br />following is the inode specification for the pipe<br />
  8. 8. Pipes & named pipes<br />structpipe_inode_info<br />{<br />wait_queue_head_t wait; //wait queue<br />char * base; //address of the FIFO buffer<br />unsigned int readers; //no of processes reading at this moment<br />unsigned int writers; //no of processes writing at this moment<br />unsigned intwaiting_readers; //no of blocked process reading at this moment<br />unsigned intwaiting_writers; //no of blocked processes writing at this moment<br />unsigned intr_counter; //no of read processes that have opened<br />unsigned intw_counter; //no of write processes that have opened<br />};<br />
  9. 9. Open a fifo<br />
  10. 10. ptrace<br />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<br />The process under control can be run step by step and its memory can be read and modified.<br />intsys_ptrace(long request, long pid, long addr, long data);<br />the function processes various request defined in the parameter request and pid indicates the process id of the process to be controlled.<br />Using the request PTRACE_TRACEME, a process can specify that its parent process controls iut via ptrace().<br />
  11. 11. Sockets <br />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.<br />Implementation of Unix domain sockets<br />Represented by a kernel data structure socket<br />Socket specific functions like Socket(), setsockout()<br />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<br />
  12. 12. Sockets <br />Operations of Unix domain sockets<br />long sys_socket(int family, int type, int protocol);// creates a socket file descriptor<br />long sys_connect(intfd, structsockaddr * uservaddr, intaddrlen); //bind the socket to the unix domain address with specified length<br />long sys_listen(intfd, int backlog);//checks whether any connections are being accepted at the server address.<br />long sys_accept(intfd, structsockaddr *upeer_sockaddr, int *upeer_addrlen));//server informs the kernel that the connections are being accepted from now on<br />long sys_getsockname(intfd, structsockaddr *usockaddr, int *usockaddr_len); //the address bound to the socket is returned.<br />
  13. 13. Sockets <br />long sys_shutdown(intfd, int how); //to shutdown but status to be given that whether the sending and receiving still allowed<br />sending and receiving from the sockets<br />Messages can be sent either as a datagram or stream of bytes<br />long sys_send(intfd, void *buff, intlen, unsigned flags);<br />long sys_sendmsg(intfd, structmsghdr *msg, unsigned int flags);<br />long sys_recv(intfd, void *buff, intlen, unsigned flags);<br />long sys_recvmsg(intfd, structmsghdr *msg, unsigned int flags)<br />