You are on page 1of 9

Program No 1 Aim To develop a program to show client server interaction <?php session_start(); ?

> <HTML><HEAD><TITLE>Test - Sessions in PHP</TITLE></HEAD> <BODY> <H2>Welcome to Sessions in PHP.</H2> <?php if (!IsSet($_SESSION[ visit_count ])) { echo "Hello, you must have just arrived. Welcome!<BR>"; $_SESSION[ visit_count ] = 1; }else { $visit_count = $_SESSION[ visit_count ] + 1; echo "Back again are ya? That makes $visit_count times now"." (not that anyone s counting)<BR>"; $_SESSION[ visit_count ] = $visit_count; } $self_url = $_SERVER[ PHP_SELF ]; $session_id = SID; if (IsSet($session_id) && $session_id) { $href = "$self_url?$session_id"; } else { $href = $self_url; } echo "<BR><A HREF=$href>Visit us again</A> sometime"; ?> </BODY></HTML> Output:

Program No 2 Aim To develop a program to generate Time Stamps of Vector Clock. #include<conio.h> #include <stdio.h> int main () { int i,j,n,t,s,x,y,p[10],r[3][10]; int tsa[3][10],tsb[3][10],tsc[3][10]; int c; n=3; //Fixing the No of Process to 3 for (i=0;i<n;i++) { printf("\n Enter The No of events(Max=10) in P%d ",i+1); scanf("%d",&p[i]); } for (i=0;i<n;i++) printf("\n No of events in P%d = %d ",i+1,p[i]); // Entring the values of Default Time Stamps for (i=0;i<n;i++)

tsc[i][j]=0. } } } // To enter Relation of Events & Manipulate printf("\n \n Enter the realtion of the corrsponding event").j+1). printf("\n For Eg a -> b for 'a' enter the value of 'b'. } } . tsb[i][j]=0. if(!tsa[i][j]==0 || tsa[i][j]>tsa[x][y]) { for(s=y. tsc[i][j]=j+1. y--. c = getch(). tsb[i][j]=0. for(j=0. for (i=0. tsc[i][j]=0.%d. \n").s<p[x].s++) tsa[x][s]=tsa[i][j].i++) { for (j=0.i+1).i++) { printf("\n :: Process %d ".&x).j++) { printf("\nEvent %d = (%d.tsc[i][j]).tsa[i][j].j<p[i]. break. } if(!tsb[i][j]==0 || tsb[i][j]>tsb[x][y]) { for(s=y.%d)" .s<p[x]. break.j<p[i]. tsb[i][j]=j+1.j++) { printf("\n Process p %d Event %d ( y / n ): ". case 1 : tsa[i][j]=0.{ for(j=0.j++) { switch (i) { case 0 : tsa[i][j]=j+1.i<n.s++) tsc[x][s]=tsc[i][j]. case 2 : tsa[i][j]=0. if(c=='Y' || c== 'y') { printf("Process ? : ").i<n.&y).j<p[i].i+1. scanf("%d".tsb[i][j].s++) tsb[x][s]=tsb[i][j].j+1. x--.s<p[x]. break. } } } } // To dislay the Value of Time Stamps for (i=0. } if(!tsc[i][j]==0 || tsc[i][j]>tsc[x][y]) { for(s=y. scanf("%d". printf("Event ? : ").

rmi. import java.0) Event 3 = (2. return 0.0.java import java. public class RObjectImpl extends UnicastRemoteObject implements RObject { public RObjectImpl() throws RemoteException { super().0.*.UnicastRemoteObject.0.co.nr) } Output Enter The No of events(Max=10) in P2 4 Enter The No of events(Max=10) in P3 2 No of events in P1 = 3 No of events in P2 = 4 No of events in P3 = 2 Enter the realtion of the corrsponding event For Eg a -> b for 'a' enter the value of 'b'.0.1) :: Process 2 Event 1 = (0.rmi.0) Event 2 = (2.4.2.4.0) Event 2 = (2.1) Event 2 = (0.3.0) Event 3 = (2.1) Event 4 = (2. } // All remote methods must throw RemoteException public void aMethod() throws RemoteException { } } . } RObjectImpl. // Programmed by.1) :: Process 3 Event 1 = (0.2) 3 Program No Aim Defining And Exporting A Remote Object in Java Program RObject.rmi.rahulsingh.getch().1.server.java import java. Process p 1 Event 1 ( y / n ): Process p 1 Event 2 ( y / n ): Process ? : 2 Event ? : 2 Process p 1 Event 3 ( y / n ): Process p 2 Event 1 ( y / n ): Process p 2 Event 2 ( y / n ): Process p 2 Event 3 ( y / n ): Process p 2 Event 4 ( y / n ): Process ? : 1 Event ? : 3 Process p 3 Event 1 ( y / n ): Process ? : 2 Event ? : 3 Process p 3 Event 2 ( y / n ): :: Process 1 Event 1 = (1.Rahul Singh (www. public interface RObject extends Remote { void aMethod() throws RemoteException.*.

/ * optionally: insert more useful stuffhere * / retumNULL.java RObjectImpl. i). NULL). (void *)i).. try { RObject robj = new RObjectImpl().. NULL. V( empty) the semaphore represents the number of resources available and is called a counting semaphore Program 5 : Simulation of Pthreads #inc1ude <pthread.h> #inc1ude <stdio.. tid). rc = pthread_create(&threads[i]. assert(O == rc).h> #inc1ude <assert. tid = (int)argument. } catch (MalformedURLException e) { } catch (UnknownHostException e) { } catch (RemoteException e) { } Now we can implement mutex_begin: P(S) mutex_end: V(S) Semaphores can be used in two ways mutual exclusion to avoid race conditions in accessing shared data in critical sections in concurrently executing processes P(S) count++ V(S) j* S only takes on values 0. thread %d!\n". } exit(EXIT _SUCCESS). assert(O == rc). printf("Hello World! It's me. i++) { printf("In main: creating thread %d\n". Naming.h> #inc1ude <stdlib. TaskCode.Output Compile the remote object implementation. 1 *j S is called a binary semaphore process synchronization (also called condition synchronization) P(empty) . } int main (int argc.h> #define NUM_THREADS 5 void *TaskCode(void *argument) { int tid. > rmic RObjectImpl Create an instance of the remote object and bind it to the RMI registry. char *argv[]) { pthread_t threads [NVM_THREADS]. / * create all threads * / for (i=O. } / * wait for all threads to complete * / for (i=O. } . i. > javac RObject. i<NVM_THREADS.rebind("//localhost/RObjectServer". i++) { rc = pthreadjoin(threads[i]. int rc.. V(full) P(full) .robj). i<NVM_THREADS.java Generate the skeletons and stubs.

like processes. fore i = 1 . just like two or more processes can. i + + ) fortj=I . for(i=1 i&lt"=4 i++) . On uniprocessor systems the kerne l uses time slicing to simulate simultaneous execution of threads in much the same way it uses time slicing with processes. clrscn). And.l. scanf("%d" .j. exit( -1).a[5] . PrintHello. NULL. t). pthread_exit(NULL). char *argvO) { pthread_t threads[NUM_ THREADS]. if (rc){ printf("ERROR.flag. each executing the function TaskCode that prints the unique number of this thread to standard output. Threads are similar to processes.c[4] [5] . tid).p[4] [5] .h> void mainO { int found. =4.j&lt.k= 1 . rc = pthread_create(&threads[t].&amp. long t. Program 6: pthread Creation and Termination #include <pthread. are time-sliced by the kernel.=5. printf("enter c1ain matrix"}. on multiprocessor systems. threads are actually able to run simultaneously. } int main (int argc. printf("Helio World! It's me. t++){ printf("ln main: creating thread %Id\n".su m=O. int rc. for(t=O.m[5] .tp). (void *)t).This program creates five threads. thread #%Id!\n". printf("enter total no of processes"). return code from pthread_createO is %d\n".h> #include <stdio. Threads. tid = (Iong)threadid. } printf("enter allocation matrix").h> #inc1ude&lt<conio.h> #define NUM THREADS 5 void *PrintHello(void *threadid) { long tid.tp. rc).j++) { scanf("%d" .i. i&lt.r[5] . t<NUM_ THREADS.c[i] [j]). POSIX (Portable Operating System Interface) threads are a great way to increase the responsiveness and performance. Program 7: Deadlock detection #inc1ude&lt<stdio.&amp. } } } pthread_exit(NULL).temp [5] .

i++ ) { sum=O . } } for(i=1"i&lt=4"i++) .j + + ) { sum+=p[i][j].r[i]).j + + ) temp[j] +=p[i] [j].j&lt.p[i] [j]).temp[j]) { flag=O. for(j = 1 . .j&lt.=5.i&lt. { for(l=l"I&ltkl++) . } } printf("deadlock causing processes are:").&amp. .i&lt. fortj = 1 . " if(i!=m[l]) { flag=l.i&lt. forU=1. for(i= 1 .i++) { scanf("%d" . } printf("enter availability vector:\n"). for(j = 1 .j&lt.&amp.i++) { scanf("%d" . } printf("enter resource vector: \n"). .. = 5. = 5. } for(i=1. k+s-: .j++) if( c[i] [j]&gt. break.=5.&amp.j&lt. temp[i]=a[i].j ++) { found=O: . =tp. for(i= 1 . } if(sum==O) { m[k]=i.j++ ) { scanf("%d" . k+»: .=5. for(j=l . } } if(flag==l) { m[k]=i.=5. .=4.j&lt.a[i]).

writing is performed signa1(wrt). while a writer is the another process that modifies or updates the shared data. } getcht). but it does not preempt an active reader PROGRAM semaphore mutex.writers problem are: 1.j). A reader has n non-preemptive priority over writers ie. In this system. readcount = 0 Readers. Reading is not performed when writer is writing 4. Initially mutex = 1. A reader gets access to the Shared data ahead of a waiting writer. wrt = 1.. } if(found==O) printf("%d \ t" . " { if(j==m[i]) found=I: . for(i=l"i&ltki++) . } OUTPUT: enter total no. . The constraints imposed on the readers. Only one write can perform writing at a single instant of time 3.writers system consists of a set of processes using some shared data.Writers Problem Writer Process wait(wrt). wrt. Many readers can perform reading concurrently 2. of processes: 4 enter claim matrix : 01001 00101 00001 10101 enter allocation matrix : 10110 11000 00010 00000 enter resource vector: 21121 enter the availability vector: 00001 deadlock causing processes are: 1 2 Program 8: Implementation of Process Synchronization Theory A readers. reader is a process that only readers shared data.

To eat a philosopher must pick up the forks placed between him. printf("\n\n\t\t * * * BEST FIT * * *\n\n").psize[lO]. clrscr().&nom).Readers.k.madd[lO].t_madd[lO]. int nom. . reading is performed wait(mutex).h> #include<conio. if (readcount == 0) signa1(wrt). readcount++ . #include<stdio. printf("\nNo. So the problem here is to design the processes in such a manner that each philosopher can be able to eat with a pair of forks under the condition that a hungry philosopher should not face indefinite waits when he decides to eat. think } while (1). Program: Shared data semaphore chopstick[g]. but here we are having 5 forks in total.Writers Problem Reader Process wait(mutex).h> voidmain() { int padd[lO]. scanf("%d" .rpsize[lO]. signa1(mutex) . signa1(mutex): Program 9 : Implementation of Dining Philosopher's Problem Theory Five philosophers are sitting around a table.n. Initially all values are 1 Philosopher i: do{ wait ( chopstick[i]) wait(chopstick[(i+1) % 5]) eat signal( chopstick[i]).j. of partitions in Memory: \t"). readcount--.t_msize[lO]. Program 10 : Simulation of paging techniques of memory management. signal(chopstick[(i+1) % 5]). if (readconnt == 1) wait(rt). A plate is kept in front of each philosopher and a fork is placed between each pair of philosopher.msize[lO].i.

i<nom. msize[j]=msize[k) . } . SIZE\t\n"). scanf(" %d" .j++ ) { if(msize [k) >msize [j]) { t_madd[j) =madd[j).&madd[i]). msize[k) =t_msize[j].msize[i]). printf("\nEnter the SIZE :\t"). madd[j)=madd[k). madd[i]+=psize[O] .i <nom.madd[i] . } for(k=O.\n ").for(i =O.i<nom. } getch().madd[i]). printf("\nADDRESS \tFREE SPACE\t\n").&msize[i]).i + + ) { printf(" \nAddress of partition: \t").k<nom. t_msize[j)=msize[j). for(i =O.printf(" was filled\n").\n \n"). msize[i]-=psize[O] . } } printf("\nAfter allocation:. scanf("%d" . printf("\nADDRESS \tA V AIL.msize[i]).madd[i].&psize [0]).printf(" %d" .j<nom.k++ ) { for(j=k.i++ ) { if(psize [0] <=msize [i]) { printf("\n partition"). for(i=O. } printf(" \nProcess SIZE: \t").i++ ) { printf("\n%d\t\t%d\n" . } } } for(i=O. printf(" \n \nBefore allocation:.break. madd[k)=t_madd[j) .i <nom.i + + ) { printf("\n%d\t\t%d\n" . scanf("%d" .