Vous êtes sur la page 1sur 1

Name: Sai Charan Gourishetty A distributed system is a collection of independent computers that appears to its users as a signal coherent

system. Process(Pipes, FIFO), Kernal(Sys-V ipc), File system persistence(POSIX IPC). msg qs Msg qs can b best dsced as internal linked list within the kernel's addr space. Msgs can be sent to the q in order and retrieved 4m the queue in several different ways. Each msg q is uniquely identified by an IPC identifier.semaphores allow processes to synchronize execution shrd mry Shrd mry cn best be described as d mapping of an area (segment) of mry that will b mapped and shrd by more than 1 process. This is by far the fastest form of IPC, bcoz there is no intermediation (i.e. a pipe, a msg q, etc). Instead, information is mapped directly from a mry segment, and into d adrsing space of the calling process. Intrnal and user DS(1.msg buffer, krnl msg struct, krnl msgid_ds,krn ipc_perm struct, 2.krnl semid_ds, krnl sem struct,3.krnl shmid_ds struct) To generate unique IPC keys : key_t ftok (char *pathname, int id); ipcrm-remove cmd int pthread_create ( pthread_t *tid, const pthread_attr_t *attr, void * (*func) (void *), void *arg); int pthread_join(pthread_t tid, void **status); int pthread_detach(pthread_t tid) void pthread_exit(void *status) int pthread_mutex_lock(pthread_mutex_t *mptr); # include <pthread.h> # define BufferSize 10 void *Producer();void *Consumer(); int BufferIndex=0;char *BUFFER; pthread_cond_t Buffer_Not_Full=PTHREAD_COND_INITIALI ZER;pthread_cond_t Buffer_Not_Empty=PTHREAD_COND_INITIA LIZER;pthread_mutex_t mVar=PTHREAD_MUTEX_INITIALIZER; int main(){pthread_t ptid,ctid; BUFFER=(char *) malloc(sizeof(char) * BufferSize);pthread_create(&ptid,NULL,Producer ,NULL);pthread_create(&ctid,NULL,Consumer,N ULL);pthread_join(ptid,NULL);pthread_join(ctid, NULL);return 0;}void *Producer(){for(;;){ pthread_mutex_lock(&mVar);if(BufferIndex==B ufferSize){pthread_cond_wait(&Buffer_Not_Full, &mVar);}BUFFER[BufferIndex++]='@';printf("P roduce : %d n",BufferIndex);pthread_mutex_unlock(&mVar); pthread_cond_signal(&Buffer_Not_Empty); }}

void*Consumer(){for(;;){pthread_mutex_lock(& mVar);if(BufferIndex==-1){ pthread_cond_wait(&Buffer_Not_Empty,&mVar) ;}printf("Consume : %d \n",BufferIndex--); pthread_mutex_unlock(&mVar); pthread_cond_signal(&Buffer_Not_Full);} END unixstr-connectionoriented like tcp, unixdgconnection less like UDP. Association-protocol, local-addr, local-process, foreign-addr, foreign-process. Half Ass - protocol, local-addr, local-process or frgn addrs, frgn prcs. Socket sys calls bind,connect,listen,accept int getpeername (int sockfd, struct sockaddr *peer, int *addrlen); int getsockname (int sockfd, struct sockaddr *me, int *addrlen); int close (int sockfd); shrd mry: int shmget(key_t key, int size, int oflag); To get permission we attach addr (down) char *shmat (int shmid, const void *shmaddr, int oflag); int shmdt (char *shmaddr); int shmctl (int shmid, int cmd, struct shmid_ds *buf);(removes shrd mry segent) msg Q : int msgget (key_t key, int msgflag); int msgsnd (int msqid, struct msgbuf *ptr,int length, int flag);int msgrcv (int msqid, struct msgbuf *ptr,int length, long msgtype, int flag); int msgctl (int msqid, int cmd, struct msqid_ds *buff); Persistance: Process - remains in existence until last process closes it. e.g., pipes and FIFOs.Kerne - remains in existence until either the kernel reboots or it is explicitly deleted. e.g., System V IPCs. File system-persistence - remains in existence until it is explicitly removed. e.g., Posix IPCs can optionally be implemented as such. Socket and Pipes both are the modes of inter process communicationin Linux or UNIX like systems.Socket is used to communicate between network processes..and kernel mediates for that..like for your internet explorer a socket is created and your Device driver(of Modem)communicates to socket for communicationpipes is another mode of bi directonal communication between processes. Pipes are fast and reliable, because they are implemented in memory on a single host where both communicating processes run. Sockets are slower and less reliable, but are much more flexible since they allow communication between processes on different hosts. Binary semophers: taken,not taken(take, release ).counting sem : neg,zero,positive (wait,signal). Mutex: not owned, owned(lock,unlock).

Vous aimerez peut-être aussi