sock_desc = scoket(AF_INET,SOCK_DGRAM,0); bind(sock_desc,(struct sockaddr *)&server,sizeof(server)); listen(scok_desc,20); new_sock = accept(sock_desc,(struct sockaddr *)&client,&len,0); connect(sock_desc,(struct sockaddr *)&to,sizeof(to)); send(sock_desc,array,sizeof(array),0); recv(sock_desc,array,sizeof(array),0); sendto(sock_desc,array,sizeof(array),0,(struct sockaddr *)&to,&len); recvfrom(sock_desc,array,sizeof(array),0,(struct sockaddr *)&from,sizeof(from)); setsockopt(sock_desc,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)); qid=msgget((key_t)1234,0666|IPC_CREAT); msgsnd(qid,&buf,512,0); msgrcv(qid,&buf,512,0,0); msgctl(qid,IPC_RMID,NULL); int pfd[2]; pipe(pfd); wite into 1 read from 0 wait(NULL) int sid = shmget((key_t)1234,35,0666|IPC_CREAT); char *shm = shmat(sid,NULL,0); int flag = shmdt(shm); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include statvfs(Path,&Data) n=((float)Data.f_bsize/(1024.0*1024.0)); k=((float)Data.f_blocks*n); l=((float)Data.f_bfree*n); a=k-l; printf("\nDisk %s",Path); printf("\nBlock size in MB:%f",n); printf("\nBlock size in bytes:%lu",Data.f_bsize); printf("\nTotal size in bytes:%lu",Data.f_blocks*Data.f_bsize); printf("\nTotal size in MB:%f",k); printf("\nTotal free blocks in MB:%f",l); printf("\nFree blocks in bytes:%lu",Data.f_bfree*Data.f_bsize); printf("\nUsed blocks in MB:%f",a); printf("\nUsed blocks in bytes:%lu\n",(Data.f_blocks*Data.f_bsize)-(Data.f_bfree*Data.f_bsize)); Finger ----------------------- 1) rpcgen finger.x 4 new files will be created 2) cc server fingerserver.c filename.srv filename.xdr -o 3) cc client fingerclient.c filename.clnt filename.xdr -o rpcgen -C myfinger.x cc -c client.c -o client.o cc -c myfinger_clnt.c -o myfinger_clnt.o cc -c myfinger_xdr.c -o myfinger_xdr.o cc -o client client.o myfinger_clnt.o myfinger_xdr.o -lnsl cc -c server.c -o server.o cc -c myfinger_svc.c -o myfinger_svc.o cc -c myfinger_xdr.c -o myfinger_xdr.o cc -o server server.o myfinger_svc.o myfinger_xdr.o -lnsl Banker: Safety Algorithm [126] STEP 1: initialize Work := Available; for i = 1,2,...,n Finish[i] = false STEP 2: find i such that both a. Finish[i] is false b. Need_i <= Work if no such i, goto STEP 4 STEP 3: Work := Work + Allocation_i Finish[i] = true goto STEP 2 STEP 4: if Finish[i] = true for all i, system is in safe state Banker: Resource-Request Algorithm [128] STEP 0: P_i makes Request_i for resources, say (1,0,2) STEP 1: if Request_i <= Need_i goto STEP 2 else ERROR STEP 2: if Request_i <= Available goto STEP 3 else suspend P_i STEP 3: pretend to allocate requested resources Available := Available - Request_i Allocation_i := Allocation_i + Request_i; Need_i := Need_i - Request_i STEP 4: if pretend state is SAFE then do a real allocation and P_i proceeds else restore the original state and suspend P_i