Sei sulla pagina 1di 56

#include<stdio.

h> main() { int i; fork(); for(i=0;i<3;i++) printf(unix\n); }

OUTPUT: [student@TECLINUX student]$ cc fork.c [student@TECLINUX student]$./a.out Unix unix unix [student@TECLINUX student]$ unix unix unix

PROGRAM: #include<stdio.h> main() { int status; if(fork()==0) execl(/bin/date,date,0); wait(&status); }

OUTPUT: [student@TECLINUX student]$ cc exec.c [student@TECLINUX student]$ ./a.out Mon mar 1 13:47:01 1ST 2011 [student@TECLINUX student]$

PROGRAM: #include<stdio.h> main() { int pid; pid=fork(); if(pid==0) { printf(Am child, My id is%d\n,getpid()); printf(My parent id is%d\n,getpid()); } else { printf(Am child, My id is%d\n,getpid()); printf(My parent id is%d\n,getpid()); } }

OUTPUT: [student@TECLINUX student]$ cc a.c [student@TECLINUX student]$ ./a.out Am child, My id is960 My parent id is960 [student@TECLINUX student]$ Am child, My id is961 My parent id is961 [student@TECLINUX student]$

PROGRAM: #include<stdio.h> main() { int child; if((child=fork()==0) { printf(child pid:%d\n,getpid()); pause(); } printf(child pid:%d\n,child); exit(child); }

OUTPUT: [student@TECLINUX student]$ cc exit.c [student@TECLINUX student]$ ./a.out child pid:2890 [student@TECLINUX student]$ child pid:2890

PROGRAM: #include<stdio.h> main() { int i=0,pid; printf(Ready to fork\n); pid=fork(); if(pid==0) { printf(child starts\n); for(i=0;i<10;i++) printf(%d\t,i); printf(child ends\n); } else { wait(0); printf(parent process); } }

OUTPUT: [student@TECLINUX student]$ cc rama.c [student@TECLINUX student]$ ./a.out Ready to fork child starts 0 1 2 3 4 5 6 child ends

PROGRAM: #include<stdio.h> #include<fcntl.h> main(int argc,char *argv[]) { int I,n,1,fd,fd1; char a[2000],b[20]; fd=open(argv[1],O_RDONLY,077); printf(\nThe contents are :\n); if(argc!=2) printf(\n error); else { while(n=(read(fd,a,2000))>0) printf(%s,a); close(fd); } }

OUTPUT: [student@TECLINUX student]$ cc close.c [student@TECLINUX student]$ ./a.out sum.c The contents are: #include<stdio.h> main() { int a,b,c; printf(\nenter the value of a,b); scanf(%d%d,&a,&b); c=a+b; printf(\n the sum of a,b is %d,c); } [student@TECLINUX student]$

PROGRAM: #include<sys/types.h> #include<sys/stat.h> #include<dirent.h> #include<pwd.h> #include<grp.h> #include<time.h> #include<locale.h> #include<langinfo.h> #include<stdio.h> #include<stdint.h> main() { struct dirent *dp; struct stat statbuf; struct passwd *pwd; struct group *grp; struct tm *tm; char datestring[256]; char dir[256]; char buff[256]; DIR *drip; printf(\n\n Enter directory Name); scanf(%s,buff); if((drip=opendir(buff))==NULL) { printf(Error); exit(1); } while(dp=readdir(drip)) { printf(%s\n,dp->d_name); if(stat(dp->d_name,&statbuf)==-1) continue; printf(%4d,statbuf.st_nlink); if((pwd=getpwuid(statbuf.st_uid))!=NULL) printf(%8.8s,pwd->pw_name); else printf(%-8,statbuf.st_uid); if((grp=getgrgid(statbuf.st_gid))!=NULL) printf(%-8.8s,grp->gr_name); else

printf(%-8d,statbuf.st_gid); printf(%9jd,(intmax_t)statbuf.st_size); tm=localtime(&statbuf.st_mtime); strftime(datestring,sizeof(datestring),n1_langinfo(D_T_FMT),tm); printf(%s%s\n,datestring,dp->d_name); } }

OUTPUT: [student@serve1 computer]$ cc ff.c [student@serve1 computer]$ ./a.out Enter directory name program . 386 computer computer 86016 sat Mar 20 08:15:25 2011. .. 6 root root 4096 Mon Feb 15 05:54:45 2011.. note.c 1 computer computer 0 sat Mar 6 06:17:21 2011 note.c [student@serve1 computer]$

PROGRAM: #include<stdio.h> #include<dirent.h> struct dirent *dptr; int main(int argc,char *argv[]) { char buff[256]; DIR *drip; printf(\n\n Enter directory name); scanf(%s,buff); if((drip==opendir(buff))==NULL) { printf(Error); exit(1); } while(dptr=readdir(drip)) if((drip=opendir(buff))=A { printf(%s\n,dptr->d_name); } }

OUTPUT: [student@serve1 computer]$ cc opendir.c [student@serve1 computer]$ ./a.out Enter directory name : welcome . .. count.c number.c next.txt fcfs.c memo.c vol.c [student@serve1 computer

PROGRAM: #include<stdio.h> #include<fcntl.h> main(int agrc,char *argv[]) { int I,n,1,fd,fd1; char a[2000],b[20]; fd=open(argv[1],O_RDONLY, 077); printf(\nthe contents are:\n); if(argc!=2) printf(\n Error); else { while(n=(read(fd,a,2000))>0) printf(%s,a); }

OUTPUT: [student@TECLINUX student]$ cc open.c [student@TECLINUX student]$ ./a.out open1.c the contents are: Hai , welcome EveryBody

PROGRAM: #include<stdio.h> #include<fcntl.h> main() { int fd; char buf[20]; fd=open(ss.txt,O_RDONLY); read(fd,buf,20); printf(The readed msg is :%s,buf); }

OUTPUT: [student@TECLINUX student]$ cc read.c [student@TECLINUX student]$ ./a.out ss.txt The readed msg is : Hai friends

PROGRAM: #include<stdio.h> #include<fcntl.h> main() { int fd,i; char buf[256]; for(i=0;i<sizeof(buf);i++); buf[i]=a; fd=open(s2.txt,O_WRONLY); write(fd,buf,sizeof(buf)); }

OUTPUT: [student@TECLINUX student]$ cc write2 .c [student@TECLINUX student]$ ./a.out [student@TECLINUX student]$ vi s2.txt

PROGRAM: #include<stdio.h> #include<dirent.h> int main() { struct dirent **namelist; int n,I; char pathname[100]; getwd(pathname); n=scandir(pathname,&namelist,0,alphasort); if(n<0) printf(error); else for(i=0;i<n;i++) printf(%s\n,namulist[i]->d_name); }

OUTPUT: [student@TECLINUX student]$ cc ls .c [student@TECLINUX student]$ ./a.out wsc.c wst.c ww.c wwe.c www xxx.c y13.c yu.c yuvi,c yuvi.c yy.c z.c zx.c zz.c [student@TECLINUX student]$

PROGRAM: #include<stdio.h> #include<string.h> int main() { FILE *f; char str[100]; char c; char word[100]; int i,flag,m,j,k; char ar[]=hi; char temp[30]; if(argv<3) { printf(usage :grep<pattern><file name>\n\n); return; } f=fopen(args[2],r); while(!feof(f)) { i=0; while(1) { fscan(f,%c,&c); if(feof(f)) { str[i++]=\0; break; } if(c==\n) { str[i++]=\0; break; } str[i++]=c; } if(strlen(str)>=strlen(args[1])) for(k=0;k<=strlen(str)-strlen(args[1]);k++) { for(m=0;m<strlen(args[1]);m++) { temp[m]=str[k+m]; } temp[m]=\0; if(strcmp(temp,args[1])==0)

{ printf(%s\n,str); break; } } } return 0; }

OUTPUT: [student@TECLINUX student]$ cc grep .c [student@TECLINUX student]$ ./a.out printf sum.c printf(Enter the two numbers to be added :); printf(\n The sum of the two numbers is :%d,c); [student@TECLINUX student]$

PROGRAM: #include<stdio.h> main() { int i,n,t=0,bt[10],t1,tat[10],w=0.wt[10]; float atat,awt; printf(Enter the total no. of process:); scanf(%d,&n); for(i=0;i<n;i++) { wt[i]=0; printf(Enter the brust time for %d the process,i+1); scanf(%d,&bt[i]); } printf(\n\tprocess\tbrust time \twaiting time\t Turn around time); printf(\n********************************************************\n); for(i=0;i<n;i++) { tat[i]=wt[i]+bt[i]; printf(\n\t%d\t\t%d\t\t%d\t\t%d\n,i+1,bt[i],wt[i],tat[i]); wt[i+1]=wt[i]+bt[i]; } for(i=0;i<n;i++) { t=tat[i]+t; w=wt[i]+w; } atat=(float)t/n; awt=(float)w/n; printf(\nAverage wating time:%f,awt); printf(\nAverage turnaround time:%f\n,atat); }

OUTPUT: [student@TECLINUX student]$ cc firstfit .c [student@TECLINUX student]$ ./a.out Enter the total no. of process:4 Enter the brust time for 1 th process:8 Enter the brust time for 2 th process:4 Enter the brust time for 3 th process:3 Enter the brust time for 4 th process:7 Process brust time waiting time Turn around time *************************************************************** 1 8 0 8 2 4 8 12 3 12 15 4 7 15 22 Average wating time : 8.750000 Average Turn around time: 14.250000 [student@TECLINUX student]$

PROGRAM: #include<stdio.h> #include<string.h> main() { int i,j,n,temp,bt[10],tat[10],w=0,r=0,s=0; float t2,t3; char pname[10][10]; char t[10]; printf(\n Enter the total no. of process); scanf(%d,&n); for(i=0;i<n;i++) { printf(\nEnter the name of process%d:,i); scanf(%s,pname[i]); } for(i=0;i<n;i++) { printf(\nEnter the brust time for process p%d:,i++); scanf(%d,&bt[i]); } for(i=0;i<n;i++) for(j=i+1;j<n;j++) { if(bt[i]>bt[j]) { temp=bt[i]; bt[i]=bt[j]; bt[j]=temp; strcpy(t,pname[i]); strcpy(pname[i],pname[j]); strcpy(pname[j],t); } } printf(\n\n\tProcess\t\tBrust time \twating time\tTurn around time); printf(\t****************************************************\n); for(i=0;i<n;i++) { tat[i]=bt[i]+w; printf(\n\t\t%s\t\t%d\t\t%d\t\t%d,pname[i],bt[i],w,tat[i]); r=r+w; w=w+bt[i]; s=s+tat[i]; } t2=(float)r/n;

t3=(float)s/n; printf(\nAverage wating time %f,t2); printf(Average trun around time %f,t3); }

OUTPUT: [student@TECLINUX student]$ cc sjfs .c [student@TECLINUX student]$ ./a.out Enter the total no. of process:4 Enter the name of process0:p1 Enter the name of process1:p2 Enter the name of process2:p3 Enter the name of process3:p4 Enter the brust time for process p1:8 Enter the brust time for process p2:6 Enter the brust time for process p3:14 Enter the brust time for process p4:3 Process Burst time wating time Turn around time *************************************************************** p4 p2 p1 p3 3 6 8 14 0 3 9 17 3 9 17 31

Average waiting time : 7.250000 Average Turn around time : 15.000000 [student@TECLINUX student]$

PROGRAM: #include<stdio.h> struct priori { int pr,br,tt,pn,wt; } a[10],temp; main() { int I,j,n,tr=0; float sum=0.0, avg=0,tat=0,at=0; printf(Enter the number of process:); scanf(%d,&n); for(i=0;i<=n;i++) { printf(Enter the brust & priority time :); scanf(%d%d,&a[i].br,&a[i].pr); a[i].pn=I; } for(i=1;i<=n;i++) { for(j=i+1;j<=n;j++) { if(a[i].pr>a[j].pr) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } for(i=1;i<=n;i++) { a[i].wt=tr; tr=tr+a[i].br; a[i].tt=tr; } printf(\nprocess no.\tBrust time\tpriority\twaiting time \Turn around time ); printf(\n*********************************************************\n); for(i=1;i<=n;i++) { printf(\n\t\%d\t\t%d\t\t%d\t\t%d\t\t%d,a[i].pn,a[i].br,a[i].pr, a[i].wt,a[i].tt); } for(i=1;i<=n;i++)

{ sum=sum+a[i].wt; tat=tat+a[i].tt; } avg=(sum/n); at=tat/n; printf(\n Average wating time :%f\n,avg); printf(\n Average turn around time :%f\n,at); }

OUTPUT: [student@TECLINUX student]$ cc sjfs .c [student@TECLINUX student]$ ./a.out Enter the no. of process:4 Enter the brust & priority time :10 3 Enter the brust & priority time :1 1 Enter the brust & priority time :2 4 Enter the brust & priority time :5 2 Process Brust time Priority waiting time turnaround time ********************************************************************* 2 1 1 0 1 4 5 2 1 6 1 10 3 6 16 3 2 4 16 18 Average waiting time :5.750000 Average turn around time : 10.250000 [student@TECLINUX student]$

PROGRAM: #include<stdio.h> typedef struct { int pno,btm,sbtm,wtm,ist; }sbcb; int main() { int pp=-1,ts,flag,count=0,ptm=0,I,n=0,twt=0,tttm=0; sbcb proc[100]; printf(\n\t Round robin Scheduling.!\t); printf(\nEnter the number of the process in the ready queue:); scanf(%d,&n); printf(Enter the time slice:); scanf(%d,&ts); printf(\n Enter the brust time %d process:,n); for(i=0;i<n;i++) { scanf(%d,&proc[i],btm); proc[i].wtm=proc[i].ist=0; proc[i].pno=i+1; proc[i].sbtm=proc[i].btm; } printf(\n process synchronisation:); do { flag=0; for(i=0;i<n;i++) { if((count=proc[i].btm)>0) { flag=-1; count=(count>=ts)?ts:count; printf(\n process %d from %d ,proc[i].pno,ptm); printf(to %d,(ptm+=count)); proc[i].btm-=count; if(pp!=i) { pp=i; proc[i].wtm+=ptm-proc[i].ist-count; proc[i].ist=ptm; } } } }while(flag);

printf(\n process number \t brust time \t waiting time \tturn around time\n); printf(************************************************************); for(i=0;i<n;i++) { twt+=proc[i].wtm; tttm+=proc[i].wtm+proc[i].sbtm; printf(\t%d\t\t%d\t\t%d\t\t,proc[i].pno,proc[i].sbtm,proc[i].wtm); printf(\%d,proc[i].wtm+proc[i].sbtm); printf(\n); } printf(\n total waiting time %d,twt); printf(\n average waiting time %f,(float)twt/n); printf(\n total around time %d,tttm); printf(\n average turn around time %f\n,(float)tttm/n); return(0); }

OUTPUT: [student@TECLINUX student]$ cc round. c [student@TECLINUX student]$ ./a.out Round Robin Scheduling..! Enter the number of the process in the ready queue:3 Enter the time slice:5 Enter the brust time 3 process:12 8 16 Process Synchronisation: Process 1 from 0to 5 Process 2 from 5to 10 Process 3 from 10to 15 Process 1 from 15to 20 Process 2 from 20to23 Process 3 from 23to 28 Process 1 from 28to 30 Process 3 from 30to3 5 Process 3 from 35to 36 process number burst time waiting time turn around time ************************************************************** 1 12 18 30 2 8 15 23 3 16 20 36 Total waiting time :53 Average waiting time:17.666667 Total turn around time :89 Average turn around time :29.666667 [student@TECLINUX student]$

PROGRAM: #include<stdio.h> #include<sys/ipc.h> #include<sys/msg.h> #include<string.h> int qid,opt; struct mm { char text[1000]; }msg; main() { squec(); while(1) { menu(); scanf(%d,&opt); switch(opt) { case 1: printf(Send message:); scanf(%s,&msg.text); msgsnd(qid,&msg,100,IPC_NOWAIT,0); break; case 2: msgrcv(qid,&receive a message:%s,msg.text); printf(receive a message :%s,msg.text): break; default: exit(0); } } } menu() { printf(\n1.send message\n); printf(\n2.receive message\n); printf(3.exit\n); } squec() { qud=msgget(0,IPC_CREAT/0666); }

OUTPUT: [student@TECLINUX student]$ cc por. c [student@TECLINUX student]$ ./ a.out 1.send message 2.receive message exit 1 send message:Hai.. 1.send message 2.receive message 3.exit 2 receive message:Hai 1.send message 2.receive message 3.exit 3 [student@TECLINUX student]$

PROGRAM: #include<string.h> #include<stdio.h> #include<fcntl.h> main() { int fd; char buf[4096]; int noc; fd=open(thulasi.txt,O_RDONLY); if(fd<0) { printf(error in pipe opening); return; } while(1) { noc=read(fd,buf,sizeof(buf)-1); if(!noc) break; buf[noc]=\0; printf(Readed messages:%s,buf); } }

OUTPUT: [student@TECLINUX student]$ cc dos. c [student@TECLINUX student]$ ./ a.out Readed messages: v r rocking

PROGRAM: #include<stdio.h> typedef int sem; sem mutex=1,full=0,empty=1; char who; int put,get; producer() { static int i=0; wait(&empty); wait(&mutex); i++; put=i; who=p; printf(PUT:%d\n,put); signal(&mutex); signal(&full); } consumer() { wait(&full); wait(&mutex); get=put; who=c; printf(GET:%d\n,get); signal(&mutex); signal(&empty); } wait(sem*s) { if(*s<=0) { if(who==p) consumer(); else producer(); } else *s=*s+1; } signal(sem*s) { *s=*s+1; } main()

{ printf(\t\t Producer consumer problem using semapore); printf(\n\n press ctrl+Z to break execution \n\n); producer(); consumer(); }

OUTPUT: [student@TECLINUX student]$ cc prod. c [student@TECLINUX student]$ ./ a.out Producer consumer problem using semapore press ctrl+Z to break execution PUT : 1 GET : 1 [student@TECLINUX student]$

PROGRAM: #include<stdio.h> int j,temp,s,n,I,a[100]; void getdata() { printf(Enter the number of memory:); scanf(%d,&n); printf(\nEnter the unallocated memory space:); for(i=0;i<n;i++) { scanf(%d,&a[i]); } } int firstfit() { getdata(); printf(\nEnter the required memory for the process:); scanf(%d,&s); for(i=0;i<n;i++) { if (a[i]>=s) { printf(The first fit the required process :%d,a[i]); break; }} } int bestfit() { getdata(); for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; }}} printf(\nEnter the required memory for the process:); scanf(%d,&s); for(i=0;i<n;i++) { if(s<=a[i]) {

printf(\n The best fit for the required process is :%d,a[i]); break; }} } int worstfit() { getdata(); for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[j]; a[j]=a[i]; a[i]=temp; }}} printf(\nEnter the memory space for the process:); scanf(%d,&s); printf(\n The worst fit for the required process is :%d,a[n-1]); } main() { int choice; printf(\t\tMemory allocations are \n); printf(1.Frist Fit \n2.Best fit\n3.Worst Fit\n4.Exit\n); a: printf(\nEnter your choice:); scanf(%d,&choice); switch(choice) { case 1: firstfit(); goto a; case 2: bestfit(); goto a; case 3: worstfit(); goto a; case 4: exit(0); } }

OUTPUT: [student@TECLINUX student]$ cc memoryalloc. c [student@TECLINUX student]$ ./ a.out Memory Allocations are 1.First Fit 2.Bestfit 3.Worst Fit 4.Exit Enter your choice:1 Enter the number of memory:3 Enter the unallocated memory space: 35 46 12 Enter the required memory for the process: 10 The First Fit the required process is: 35 Enter your choice:2 Enter the number of memory:3 Enter the unallocated memory space: 35 46 50 Enter the required memory for the process: 49 The First Fit the required process is: 50 Enter your choice:3 Enter the number of memory:3 Enter the unallocated memory space: 35 56 73 Enter the required memory for the process: 54 The First Fit the required process is: 73 Enter your choice:4 [student@TECLINUX student]$

PROGRAM: #include<stdio.h> int n,i,j,k,flag,count=0,refer[100],page_frame[100][2],fault=0,min,no_frames; void replace(int Z) { for(i=0;i<n;i++) { flag=1; for(j=0;j<no_frames;j++) if(refer[i]==page_frame[j][0]) { m=j; flag=0; } if(flag) { fault++; min=32000; for(j=0;j<no_frames;j++) if(page_frame[j][1]<min) { min=page_frame[j][1]; k=j; } page_frame[k][0]=refer[i]; page_frame[k][1]=++count; for(j=0;j<no_frames;j++) printf(%d,page_frame[j][0]); printf(\n); } else { printf(no page fault\n); if(Z==2) page_frame[m][1]=++count; } } printf(number of pages fault is %d\n,fault); } int main() { printf(\n Enter the no of process:); scanf(%d,&n); printf(\nenter the no of frames:); scanf(%d,&no_frames);

printf(\nEnter the reference_string:); for(i=0;i<n;i++) scanf(%d,&refer[i]); printf(\t\t\t FIFO ALGORITHM\n); for(i=0;i<no_frames;i++) { page_frame[i][0]==-1; page_frame[i][1]=count; } replace(1); fault=0; count=0; printf(\t\t\t LRU ALGORITHMS\n); for(i=0;i<no_frames;i++) { page_frame[i][0]=-1; page_frame[i][1]=count; } replace(2); return 0; }

OUTPUT: [student@TECLINUX student]$ cc memory. c [student@TECLINUX student]$ ./ a.out Enter the no of process: 20 Enter the no of frames: 3 Enter the reference_string:7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1

FIFO ALGORITHM 700 no page fault 710 712 012 032 no page fault 034 234 no page fault 204 203 no page fault 103 123 120 no page fault 720 no page fault 710 number of page fault is 14

LRU ALGORITHM 7-1-1 70-1 701 201 no page fault 203 no page fault 403 402 432 032 no page fault no page fault 132 no page fault 102 no page fault 107 no page fault no page fault number of page fault is 12 [student@TECLINUX student]$

PROGRAM: #include<stdio.h> #include<graphics.h> #include<stdlib.h> #include<conio.h> #define BL 30 #define BW 15 #define SX 140 #define SY 100 typedef struct { char name[10]; int st_blk; int len,fcolor; } file_info; int cols[]={GREEN,MAGENTA,BLUE,CYAN,RED}; file_info f[10]; int n; void read _file() { int i; printf(\nHow Many File:); scanf(%d,&n); printf(\nEnter the details:); for(i=0;i<n;i++) { printf(\n File Name:); fflush(stdin); gets(f[i].name); printf(\n Starting Block:); scanf(%d,&f[i].st_blk); printf(\n Length :); scanf(%d,&f[i].len); f[i].fcolor=cols[i]; }} void fill_space() { int I,b,x1,y1; for(i=0;i<n;i++) { for(b=f[i].st_blk;st_blk+f[i].len;b++) { setfillstyle(1,f[i].fcolor); x1=SX+(b%7)*50;

y1=SY+(b/7)*40; bar3d(x1,y1,x1+BL,y1+BW,1, 2); }}} viod design_disk() { int i,j,x1,y1; char s[5]; setcolor(LIGHLGREEN); settextstyle(1,0,3); settextjustify (1,1); outtextxy(320,20,Contiguous File Alocation); setcolor(14); settextstyle(2,0,3); settextjustify(1,1); for(i=0;i<7;i++) { for(j=0;j<7;j++) { x1=SX+j*50; y1=SY+i*40; rectangle(x1,y1,x1+BL,y1+BW); sprintf(s,%d,i*7+j); outtextxy(x1+BL/2,y1+BW+10,s); }} rectangle(SX-20,SY-20,SX+350,SY+280); settextstyle(1,0,2); for(i=0;i<n;i++) { setcolor(f[i].fcolor); outtextxy(100,400+i*20,f[i].name); } setcolor(14); } void main() { int gd,gm; gd=DETECT; initgraph(&gd,&gm,c:/tc/bgi); rondomize(); read_file(); design_disk(); fill_space(); getch(); closegraph(); }

OUTPUT: How many files: 2 Enter the Details: File name: A Start block: 1 Length: 3 File name: B Start block: 6 Length: 5

Potrebbero piacerti anche