first

Tuesday, 31 October 2017

PRODUCER CONSUMER PROBLEM IN C using semaphore and Thread

#include<stdio.h>
#include<pthread.h>
#include<semaphore.h>
#include<unistd.h>

int buf[10];
sem_t mutex,full,empty;



void* producer()
{
    int i;
    for(i=0;i<10;i++)
    {
       
       
   
        sem_wait(&empty);
        sem_wait(&mutex);
        buf[i]=i;
        printf("\nProduced : %d",i);
        sem_post(&mutex);
        sem_post(&full);
        sleep(1);
    }
    pthread_exit("prodused");
}
void* consumer()
{
    int j;
    for(j=0;j<10;j++)
    {
       
        sem_wait(&full);
       
        sem_wait(&mutex);
        printf("\nconsuming item: %d\n",buf[j]);
        sem_post(&mutex);
        sem_post(&empty);
        sleep(6);
    }
    pthread_exit("consumed");
}
void main()
{
    pthread_t t1,t2;

    sem_init(&mutex,0,1);
    sem_init(&full,0,0);
    sem_init(&empty,0,5);

    pthread_create(&t1,NULL,producer,NULL);
    pthread_create(&t2,NULL,consumer,NULL);
    pthread_join(t1,NULL);
    pthread_join(t2,NULL);
}



Friday, 22 September 2017

Single level Directory in c

/*copy Right @ shyam reghu and shyamtr.blogspot.in */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int i=0,j=0;
char dp[100];
struct dir
{
    char dname[100];
    char fname[100][100];
    int fcnt;
}dir;
void create()
{
    char dp[100];
    printf("Enter the file name :\t");
    scanf("%s",dp);
    printf("sss");
    for(i=0;i<dir.fcnt;i++)
    {
        printf("sss");
        if(strcmp(dp, dir.fname[i])==0)
        {
            printf("File %s already exist please enter another name\n\n\n ", dp);break;
        }
    }
    if(i==dir.fcnt)
    {
        strcpy(dir.fname[dir.fcnt],dp);
        printf("\n\nfile added to the directory successfully...\n\n\n");
    }
    dir.fcnt++;
   
}   
void delete()
{    char dp[100];
    printf("\n Enter the name of the file to delete:\t");
    scanf("%s",dp);
    for(i=0;i<dir.fcnt;i++)
    {
        if(strcmp(dp, dir.fname[i])==0)
        {
            printf("File %s is deleted \n",dp);
            strcpy(dir.fname[i],dir.fname[dir.fcnt-1]);break;
        }
    }
    if(i==dir.fcnt)
    {
        printf("File %s not found\n\n",dp);
    }
    else
    {
        dir.fcnt--;
    }
}
void search()
{
    char dp[100];
    printf("\n Enter the name of the file :\t");
    scanf("%s",dp);
    for(i=0;i<dir.fcnt;i++)
    {
        if(strcmp(dp, dir.fname[i])==0)
        {
            printf("File %s is found ", dp);break;
        }
    }
    if(i==dir.fcnt)
    {
        printf("File %s not found",dp);
    }
}
void display()
{
    if(dir.fcnt==0)
    printf("\n Directory Empty");
    else
    {
        printf("\n List of files in the file directory is :\n\t");
        for(i=0;i<dir.fcnt;i++)
        printf("\t%s\n\t",dir.fname[i]);
        printf("\n");
    }
}
void main()
{
    int ch,i=0;
    printf("\nEnter name of directory :\t ");
    scanf("%s", dir.dname);
    dir.fcnt=0;
    while(1)
    {
        printf("\n\t Enter your choice\n");
        printf("\t\t~~~~~~~~~~~~~~~~~~~~\n");
        printf("\t\t* 1. Create File  *\n");
        printf("\t\t* 2. Delete File  *\n");
        printf("\t\t* 3. Search File  *\n");
        printf("\t\t* 4. Display File *\n");
        printf("\t\t* 5. Exit         *\n");
        printf("\t\t~~~~~~~~~~~~~~~~~~~~\n");
        scanf("%d",&ch);
        switch(ch)
        {
            case 1:
                    create(); break;
            case 2:
                    delete(); break;
            case 3:
                    search(); break;
            case 4:
                    display(); break;
            case 5:
                    exit(0);
            default :
                    printf(" Wrong entry...please try again\n");
        }
    }
}

Wednesday, 20 September 2017

priority scheduling algorithm in C | non-preemptive | non-preemptive priority scheduling algorithm in c program | priority scheduling algorithm with Gantt chart in C

/*Copy Right SHYAM REGHU $$$ shyamtr.blogspot.com */#include<stdio.h>
void main()
{
 int n,i,j,TEMP,TEMP1,TEMP2,TEMP3,TEMP4;
 float WTSUM=0,TATSUM=0;
 int bt[10],at[10],P[10],ct[10],tat[10],wt[10],pt[10];
 printf("enter the no of  process\n");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
  printf("Enter the arrival time of p%d:\t",i);
  scanf("%d",&at[i]);
  printf("Enter burst time of p%d: \t",i);
  scanf("%d",&bt[i]);
  printf("Enter the priority :\t");
  scanf("%d",&pt[i]);
  P[i]=i;
  printf("\n");
 }
 ct[0]=0;
    if(bt[1]>=at[n])
    {
        ct[1]=bt[1]+at[1];
        tat[1]=ct[1]-at[1];
        wt[1]=tat[1]-bt[1];
  WTSUM=wt[1];
  TATSUM=tat[1];
        for(i=2;i<=n;i++)
        {
            for(j=i+1;j<=n;j++)
            {
                if(pt[j]<pt[i])
                {
                    TEMP4=pt[i];
                    pt[i]=pt[j];
                    pt[j]=TEMP4;
                    TEMP1=bt[i];
                    bt[i]=bt[j];
                    bt[j]=TEMP1;
                    TEMP2=at[i];
                    at[i]=at[j];
                    at[j]=TEMP2;
                    TEMP3=P[i];
                    P[i]=P[j];
                    P[j]=TEMP3;
                }
            }
                if(ct[i-1]<at[i])
                {
                    TEMP=at[i]-ct[i-1];
                    ct[i]=ct[i-1]+bt[i]+TEMP;
                    TEMP1=bt[i];
                }
                else
                {
                    ct[i]=ct[i-1]+bt[i];
                }
                tat[i]=ct[i]-at[i];
                wt[i]=tat[i]-bt[i];
                WTSUM=WTSUM+wt[i]+wt[1];
                TATSUM=TATSUM+tat[i]+tat[1];
       }
   }
            if(at[n]==0)
            {
            ct[0]=0;
            for(i=1;i<=n;i++)
                {
                    for(j=i+1;j<=n;j++)
                    {
                        if(pt[j]<pt[i])
                        {
                            TEMP4=pt[i];
                            pt[i]=pt[j];
                            pt[j]=TEMP4;
                          TEMP1=bt[i];
                          bt[i]=bt[j];
                          bt[j]=TEMP1;
                        TEMP2=at[i];
                        at[i]=at[j];
                        at[j]=TEMP2;
                        }
                    }
                if(ct[i-1]<at[i])
                {

                    TEMP=at[i]-ct[i-1];
                    ct[i]=ct[i-1]+bt[i]+TEMP;
                    TEMP1=bt[i];
                }
                else
                {
                    ct[i]=ct[i-1]+bt[i];
                }
            tat[i]=ct[i]-at[i];
            wt[i]=tat[i]-bt[i];
            WTSUM=WTSUM+wt[i];
           TATSUM=TATSUM+tat[i];
        }
    }
 printf("\n\n\n");
 printf("\tPROCESS\tBT\tAT\tPT\tTATshyam\tWT\n");
 for(i=1;i<=n;i++)
 {
 printf("\tP%d\t%d\t%d\t%d  \t%d\t%d\n\n",P[i],bt[i],at[i],pt[i],tat[i],wt[i]);
 }
 printf("Average_waiting_time = %f\n",WTSUM/n);
 printf("Average_turn_around_time= %f\n",TATSUM/n);
 printf("\n\n");
 printf("Gantt chart\n");
 for(i=1;i<=n;i++)
 {
  printf("\tP%d\t",P[i]);

 }
 printf("\n");
 for(i=1;i<=n;i++)
 {
 printf("\t%d\t",ct[i]);
 }
}
//shyamtr.blogspot.com KTU 

Round Robin Scheduling program in C | Round Robin scheduling Algorithm with Gantt chart c program|scheduling algorithms

/*Copy right SHYAM REGHU $$http://shyamtr.blogspot.in/*/
#include<stdio.h>
int at[100],bt[100],rt[100],temp[100];
float wait_time=0,turn_time=0;
void main()
{
 int c,j,n,time,r,flag=0,time_q,ltt,i,wt=0;
 printf("Enter no.of process:");
 scanf("%d",&n);
 r=n;
 for(c=0;c<n;c++)
 {
  printf("Enter arrival time of p%d:\t",c+1);
  scanf("%d",&at[c]);
  printf("Enter burst time of p%d: \t",c+1);
  scanf("%d",&bt[c]);
  rt[c]=bt[c];
  temp[c]=bt[c];
  printf("\n");
 }
 printf("Enter time quantum:\t");
 scanf("%d",&time_q);
 printf("\n\n\tprocess\tAT\tTAT\tWT shyam\n\n");
 for(time=0,c=0;r!=0;)
 {
  if(rt[c]<=time_q && rt[c]>0)
  {
  time=time+rt[c];
  rt[c]=0;
  flag=1;
  }
  else if (rt[c]>0)
  {
   rt[c]=rt[c]-time_q;
   time=time+time_q;
  }
  if(rt[c]==0 && flag==1)
  {
   wt=0;
   wt=time-at[c]-bt[c];
   r--;
   printf("\tP%d\t%d\t%d\t%d\n",c+1,at[c],time-at[c],wt);//http://shyamtr.blogspot.in/
   ltt=time-at[c];
   wait_time=wait_time+time-at[c]-bt[c];
   turn_time=turn_time+time-at[c];
   flag=0;
  }
  if(c==n-1)
   c=0;
  else if(at[c+1]<=time)
   c++;
  else
   c=0;
 }
 j=0;
 printf("\n\n\n"); 
 printf("Gantt Chart ");
  printf("\n\n\n"); 
 printf("\t");
 for(i=at[0];i<time;)
 {
  if(bt[j]>=time_q)
  {
   printf("P%d\t",j+1);
   i+=time_q;
   bt[j]=bt[j]-time_q;
  }
  else if(bt[j]>0)
  {
   printf("p%d\t",j+1);
   i+=bt[j];
   bt[j]=0;
  }
  j++;
  if(j>=n)
  {
   j=0;
  }
 }
printf("\n");

j=0;
 printf("\t");
for(i=at[0];i<time;)
 {
  if(temp[j]>=time_q)
  {
   printf("%d\t",i+time_q);
   i+=time_q;
   temp[j]=temp[j]-time_q;
  }
  else if(temp[j]>0)
  {
   printf("%d\t",i+temp[j]);
   i+=temp[j];
   temp[j]=0;
  }
  j++;
  if(j>=n)
  {
   j=0;
  }
 }

  printf("\n\n\n"); 
 printf("\nAverage_waiting_time=%f\n",wait_time/n);
 printf("Average_turn_around_time=%f\n",turn_time/n);
 printf("\n\n");
}
/*http://shyamtr.blogspot.in/*/

Wednesday, 6 September 2017

shortest job first (SJF) also known as | Shortest job next (SJN) or | shortest process next (SPN) scheduling algorithm | c program error free|

#include<stdio.h>
#define S 20
void main()
{
int bt[S],at[S],sum_bt=0,smallest,n,i,j,wt[S],ct[S],p[S],w=-1;
  int sum_turnaround=0,sum_wait=0;
float awt,att;
  printf("Enter no of processes : ");
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    printf("Enter burst time and arrival time for proces P%d : ",i+1);
    scanf("%d %d",&bt[i],&at[i]);
    sum_bt+=bt[i];
  }
  printf("\n\nProcess\t|\tBT\t|\tAT\t|\tCT\t| Waiting Time|Turnaround Time\n\n");
  for(j=0;j<sum_bt;)
  {
    smallest=n-1;
    for(i=0;i<n;i++)
    {
      if(at[i]<=j && bt[i]>0 && bt[i]<bt[smallest])
        smallest=i;
    }
    if(smallest==S-1)
    {
      j++;
      continue;
    }
    printf("P[%d] \t|\t %d \t|\t%d\t|\t%d\t|\t%d\t%d\n",smallest+1,bt[smallest],at[smallest],at[smallest]+j+bt[smallest]-at[smallest],j-at[smallest],j+bt[smallest]-at[smallest]);
w++;
p[w]=smallest+1;
ct[w]=(j+bt[smallest]-at[smallest])+at[smallest];
    sum_turnaround+=j+bt[smallest]-at[smallest];
    sum_wait+=j-at[smallest];
    j+=bt[smallest];
    bt[smallest]=0;
  }
  for(i=0;i<n;i++)
  {
  printf("\tp%d",p[i]);
  }
printf("\nat[\t");
  for(i=0;i<n;i++)
  {
  printf("%d\t",ct[i]);
  /*printf("");*/
  }
awt=sum_wait*1.0/n;
att=sum_turnaround*1.0/n;
  printf("\n\n average waiting time = %f",awt);
  printf("\n\n average turnaround time = %f",att);
}

Sunday, 18 June 2017

COMPUTER SCIENCE AND ENGINEERING (KTU) TUITION

Are you a B.tec CSE student of KTU( APJ Abdul Kalam Technological University )?
CRASH COURSE for SUPPLEMENTARY ( 2nd Year ) 2017
Offering SUPPLEMENTARY  tuition for Semester 3/4 (2nd Year) 
for Data Structure , Operating Systems , Principles of Database Design , Java & C programming,  any  ONE of the above subjects.
Click Here To register

place : CHERUTHONI IDUKKI, HOME TUITION and also in Ettumanoor, Kaduthuruthy, Thalayolaparambu, KOTTAYAM

Friday, 17 March 2017

NN KAKKAD | SABHALAMEE YATHRA| KAVITHA| One Of My favorite Poem ......

സഫലമീ യാത്ര

 
എന്‍എന്‍കക്കാട്‌ 


ആര്‍ദ്രമീ ധനുമാസ രാവുകളിലോന്നില്‍
ആതിര വരും പോകുമല്ലേ സഖീ . . .
ഞാനീ ജനലഴി പിടിച്ചൊട്ടു നില്‍ക്കട്ടെ
നീയെന്നണിയത്തു തന്നെ നില്‍ക്കൂ
ഈ പഴങ്കൂടൊരു ചുമയ്ക്കടി ഇടറി വീഴാം

വ്രണിതമാം കണ്൦തില് ഇന്ന് നോവിത്തിരി കുറവുണ്ട്
വളരെ നാള്‍ കൂടി ഞാന്‍ നേരിയ നിലാവിന്റെ,
പിന്നിലെ അനന്തതയില്‍ അലിയും ഇരുള്‍ നീലിമയില്‍
എന്നോ പഴകിയൊരോര്‍മ്മകള്‍ മാതിരി
നിന്നു വിറക്കുമീ ഏകാന്ത താരകളെ
ഇങ്ങൊട്ടു കാണട്ടെ നീ തൊട്ടു നില്‍ക്കൂ

ആതിര വരും നേരം ഒരുമിച്ച് കൈകള്‍ കോര്‍ത്ത്‌
എതിരെല്‍ക്കണം നമുക്കിക്കുറി
വരും കൊല്ലമാരെന്നും എന്തെന്നുമാര്‍ക്കറിയാം . . .

എന്ത് , നിന്‍ മിഴിയിണ തുളുമ്പുന്നുവോ സഖീ . . .
ചന്തം നിറക്കുകീ ശിഷ്ട ദിനങ്ങളില്‍
മിഴിനീര്‍ ചവര്‍പ്പ് പെടാതീ
മധുപാത്രം അടിയോളം മോന്തുക
നേര്‍ത്ത നിലാവിന്റെ അടിയില്‍ തെളിയുമിരുള്‍ നോക്ക്
ഇരുളിന്റെ മറകളിലെ ഓര്‍മ്മകളെടുക്കുക
ഇവിടെ എന്തോര്‍മ്മകളെന്നോ . . .

നിറുകയിലിരുട്ടെന്തി പാറാവ്‌ നില്‍ക്കുമീ
തെരുവ് വിളക്കുകള്‍ക്കപ്പുറം
പധിതമാം ബോധത്തിനപ്പുറം
ഓര്‍മ്മകള്‍ ഒന്നും ഇല്ലെന്നോ ഒന്നുമില്ലെന്നോ . . .

പല നിറം കാച്ചിയ വളകള്‍ അണിഞ്ഞും അഴിച്ചും
പല മുഖം കൊണ്ട് നാം തമ്മില്‍ എതിരേറ്റും
നൊന്തും  പരസ്പരം നോവിച്ചും
പതിറ്റാണ്ടുകള്‍ നീണ്ടോരീ
അറിയാത്ത വഴികളില്‍ എത്ര കൊഴുത്ത
ചവര്‍പ്പ് കുടിച്ചു വറ്റിച്ചു നാം
ഇത്തിരി ശാന്തി തന്‍ ശര്‍ക്കര നുണയുവാന്‍
ഓര്‍മ്മകളുണ്ടായിരിക്കണം
ഒക്കെയും വഴിയോര കാഴ്ചകളായി
പിറകിലേക്കോടി മറഞ്ഞിരിക്കാം
പാതിയിലേറെ കടന്നുവല്ലോ വഴി
പാതിയിലേറെ കടന്നുവല്ലോ വഴി . . .

ഏതോ പുഴയുടെ കളകളത്തില്‍
ഏതോ മലമുടി പോക്കുവെയിലില്‍
ഏതോ നിശീഥത്തിന്‍ തേക്ക് പാട്ടില്‍
ഏതോ വിജനമാം വഴി വക്കില്‍ നിഴലുകള്‍
നീങ്ങുമൊരു താന്തമാം അന്തിയില്‍
പടവുകളായി കിഴക്കേറെ ഉയര്‍ന്നു പോയി
കടു നീല വിണ്ണില്‍ അലിഞ്ഞുപോം മലകളില്‍

പുളയും കുരുത്തോല തെളിയുന്ന പന്തങ്ങള്‍
വിളയുന്ന മേളങ്ങള്‍ ഉറയുന്ന രാവുകളില്‍
എങ്ങാനോരൂഞ്ഞാല്‍ പാട്ട് ഉയരുന്നുവോ സഖീ
എങ്ങാനോരൂഞ്ഞാല്‍ പാട്ട് ഉയരുന്നുവോ . . .
ഒന്നുമില്ലെന്നോ . . . ഒന്നുമില്ലെന്നോ . . .

ഓര്‍മ്മകള്‍ തിളങ്ങാതെ മധുരങ്ങള്‍ പാടാതെ
പാതിരകള്‍ ഇളകാതെ അറിയാതെ
ആര്‍ദ്രയാം ആര്‍ദ്ര വരുമെന്നോ സഖീ
അര്‍ദ്രയാം ആര്‍ദ്ര വരുമെന്നോ സഖീ . . .

ഏതാണ്ടൊരോര്‍മ്മ വരുന്നുവോ
ഓര്‍ത്താലും ഓര്‍ക്കാതിരുന്നാലും
ആതിര എത്തും കടന്നുപോയീ വഴി
നാമീ ജനലിലൂടെതിരെല്‍ക്കും
ഇപ്പഴയോരോര്‍മ്മകള്‍ ഒഴിഞ്ഞ താളം
തളര്‍ന്നൊട്ടു വിറയാര്‍ന്ന കൈകളിലേന്തി
അതിലൊറ്റ മിഴിനീര്‍ പതിക്കാതെ മനമിടറാതെ . . .

കാലമിനിയുമുരുളും വിഷു വരും
വര്‍ഷം വരും തിരുവോണം വരും
പിന്നെയോരോ തളിരിനും പൂ വരും കായ് വരും
അപ്പോളാരെന്നും എന്തെന്നും ആര്‍ക്കറിയാം
നമുക്കിപ്പോഴീ ആര്‍ദ്രയെ ശാന്തരായി
സൗമ്യരായി എതിരേല്‍ക്കാം
വരിക സഖീ അരികത്തു ചേര്‍ന്ന് നില്‍ക്കൂ . . .
പഴയൊരു മന്ത്രം സ്മരിക്കാം
അന്യോന്യം ഊന്നുവടികളായി നില്‍ക്കാം
ഹാ സഫലമീ യാത്ര
ഹാ സഫലമീ യാത്ര . . . ! ! !

Round Robin Scheduling program in C | Round Robin scheduling Algorithm with Gantt chart c program|scheduling algorithms

/*Copy right SHYAM REGHU $$http://shyamtr.blogspot.in/*/ #include<stdio.h> int at[100],bt[100],rt[100],temp[100]; float wait_time=0,...