Posts

Showing posts from August, 2013
/*Implementation of peterson's solution using pthread API in LINUX*/ #include<stdio.h> #include<pthread.h> #include<unistd.h> #include<stdbool.h> /*for declaring boolean variables*/ #define SIZE 100 int turn; bool flag[2]; void *process1(); int main() {     int i=SIZE,j=1;     pthread_t tid;     pthread_attr_t attr;     pthread_attr_init(&attr);     pthread_create(&tid,&attr,&process1,NULL);/*new thread created*/     do     {         flag[0]=1; /* i.e true*/         turn=1;         printf("\nProcess 0 is waiting...\n");         while(flag[1]&&turn==1)         ;         printf("\nProcess 0 is in critical section...\n");  ...
///PROGRAM TO IMPLEMENT PRIORITY SCHEDULING #include<stdio.h> #include<conio.h> #define MAX 20 struct proces {  int burst;  char name[MAX];  int prio;  }; int main() {  struct proces arr[MAX],temp;  int n,i,j,sum,start[MAX],finish[MAX],wait[MAX],turn[MAX];  float avgwait=0.0,avgturn=0.0;  printf("\n\tEnter the number of process\t");  scanf("%d",&n);  for(i=0;i<n;i++)  {    printf("\n\tEnter process name for process P%d\t",i+1);    scanf("%s",arr[i].name);    printf("\n\tEnter priority for process P%d\t",i+1);    scanf("%d",&arr[i].prio);    printf("\n\tEnter burst time for process P%d\t",i+1);    scanf("%d",&arr[i].burst);  }  //sort for(i=0;i<n;i++)  {    for(j=i;j<n;j++)     {       if(arr[i].prio>arr[j].prio)     {         tem...
//PROGRAM TO IMPLEMENT SJF(SHORTEST JOB FIRST) SCHEDULING #include<stdio.h> #include<conio.h> #define MAX 20 int main() {  char pname[MAX][MAX],tname[MAX];  int burst[MAX],wait[MAX],finish[MAX],start[MAX],turn[MAX],i,j,n,sum;  float avgwait=0.0,avgturn=0.0;  printf("\n\tEnter the number of process\t");  scanf("%d",&n);  for(i=0;i<n;i++)  {    printf("\n\tEnter process name of process P%d\t",i+1);    scanf("%s",pname[i]);    printf("\n\tEnter Burst time of processP%d\t",i+1);    scanf("%d",&burst[i]);  }   // sorting   for(i=0;i<n;i++)   {    for(j=i;j<n;j++)    {     if(burst[i]>burst[j])       {     sum=burst[i];     burst[i]=burst[j];     burst[j]=sum;     strcpy(tname,pname[i]);     strcpy(pname[i],pname[j]);   ...