Operating Systems Laboratory Manual - AIDS
Operating Systems Laboratory Manual - AIDS
3. Process Management using System Calls: Fork, Exit, Getpid, Wait, Close 17
16. Install any guest operating system like Linux using VMware. 111
ADDITIONAL EXPERIMENT
1
Ex. No: 1 Installation of windows operating system
1. Drive Selection
Figure 1. Drive Selection step (for Windows)
Attention: The selected drive will be formatted during the installation. Back up all data on it before the installation.
Note: The drivers will be installed automatically after the OS installation. It is recommended to restart your server
to ensure that all installed drivers take effect.
2
2. OS Selection
The IP address is made up of four parts separated by dots. The following table lists the valid value range for each
part.
3. Installation Settings
3
Administrator Password: You can change your administrator password later from the operating system.
If you want to do advanced configurations, expand the list by clicking the arrow icon next to Advanced.
4
Refer to the following table for the valid values when you type the required address information.
Components: You can select one or more components for installation according to your requirements.
Include run-once commands: If you want to run specified commands at the end of the installation process, select
the check box. A command-type area is displayed. Type one command and click Add. The command is added to
the command list. You can add five commands at most. If you want to remove a certain command, select it and
click Remove. The commands in the command list will be run one time only and in the order you type them.
4. Partition Options
5
If no existing partition is detected on the drive, select Repartition the drive during installation.
5. Summary
6
/* 1. Simulation of ls command */ #include<dirent.h> #include<stdio.h>
main()
{
char dirname[10];
DIR *p;
struct dirent *d;
printf("Enter directory name ");
scanf("%s",dirname);
p=opendir(dirname);
if(p==NULL)
{
perror("Cannot find dir.");
exit(-1);
}
while(d=readdir(p))
printf("%s\n",d->d_name);
}
7
OUTPUT:
enter directory name iii
.
..f2
f1
8
/* 2. Simulation of grep command */
#include<stdio.h>
#include<string.h>
main()
{
char fn[10],pat[10],temp[200];
FILE *fp;
printf("\n Enter file name : ");
scanf("%s",fn);
printf("Enter the pattern to be searched : ");
scanf("%s",pat);
fp=fopen(fn,"r");
while(!feof(fp))
{
fgets(temp,1000,fp);
if(strstr(temp,pat))
printf("%s",temp);
}
fclose(fp);
}
9
OUTPUT:
enter file name: file4
enter the pattern to be searched: roll
roll no percentage grade
10
/* using - open ,read and write system calls
file copy operation*/
#include<stdio.h>
#include<fcntl.h>
main()
{
char buf[1000],fn1[10],fn2[10];
int fd1,fd2,n;
printf("Enter source file name ");
scanf("%s",fn1);
printf("Enter destination file name ");
scanf("%s",fn2);
fd1=open(fn1,O_RDONLY);
n=read(fd1,buf,1000);
fd2=open(fn2,O_CREAT|0666);
n=write(fd2,buf,n);//write file
close(fd1);
close(fd1);
}
11
OUTPUT:
enter source file name
vrscet.txt
enter destination file name
cse
[it2-20@localhost ~]$ cat cse
12
PROGRAMCODING:
13
OUTPUT:
[2mecse25@rhes3linux ~]$ sh pg2.sh
Enter theavale
10
Enter b value
50
sum: 60
sub: -40
mul: 500
div: 0
14
PROGRAMCODING:
num="1 2 3 4 5 6 7 8"
for n in $num
do
q=`expr $n % 2`
if [ $q -eq 0 ]
then
echo "even no"
continue
fi
echo "odd no"
done
15
OUTPUT:
16
PROGRAMCODING:
echo "which table you want"
read n
for((i=1;i<10;i++))
do
echo $i "*" $n "=" `expr $i \* $n`
done
17
OUTPUT:
18
PROGRAMCODING:
a=1
while [ $a-lt 11 ]
do
echo "$a"
a=`expr$a +1`
done
19
OUTPUT:
20
PROGRAMCODING:
for var1 in 1 2 3
do
for var2 in 0 5
do
if [ $var1 -eq 2 -a $var2 -eq 0 ]
then
continue
else
echo "$var1 $var2"
fi
done
21
OUTPUT:
22
PROGRAMCODING:
add()
{
c=`expr$1 +$2`
echo"addition = $c"
}
add 5 10
23
OUTPUT:
[2mecse25@rhes3linux ~] sh pg2.sh
addition = 15
24
PROGRAMCODING
ch='y'
while [ $ch = 'y']
do
echo "enter your choice"
echo "1 no of user loged on" echo "2 print calender"
echo "3 print date" read d
case $d in
1) who | wc - l;;
2) cal 20;;
3) date;;
*) break;;
esac
echo "do you wish to continue(y/n)"
read ch
done
25
OUTPUT:
[2mecse25@rhes3linux ~]$ sh case2.sh
Enter you rchoice
1 no of user loged on
2 print calender
3 print date
Thu Apr4 11:18:20IST2013 do you wish to continue(y/n)
n
26
Program : fork()
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
main(void)
pid\_t pid = 0;
pid = fork();
if (pid == 0) {
if (pid > 0) {
if (pid < 0) {
perror("In fork():");
exit(0);
cc probe1.c -o probe1
kris@linux:/tmp/kris> ./probe1
I am the child.
I am the parent, the child is 16959.
27
Program : wait()
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
main(void) {
pid\_t pid = 0;
int status;
pid = fork();
if (pid == 0) {
sleep(10);
if (pid > 0) {
pid = wait(&status);
if (WIFEXITED(status)) {
if (WIFSIGNALED(status)) {
28
}
if (pid < 0) {
perror("In fork():");
exit(0);
cc probe2.c -o probe2
kris@linux:/tmp/kris> ./probe2
I am the child.
29
Program : exec()
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
main(void) {
pid = fork();
if (pid == 0) {
if (pid > 0) {
pid = wait(&status);
if (WIFEXITED(status)) {
if (WIFSIGNALED(status)) {
if (pid < 0) {
30
perror("In fork():");
exit(0);
cc probe3.c -o probe3
kris@linux:/tmp/kris> ./probe3
I am the child.
total 36
31
PROGRAM:
#include<stdio.h>
void main()
{
int i,tbt=0,nop,ts=0,flag[20], rem[20];
int from,wt[20],tt[20],b[20], twt=0,ttt=0;
int dur;
float awt,att;
printf("Enter no. of Processes: ");
scanf("%d",&nop);
printf("Enter the time slice: "); scanf("%d",&ts);
printf("Enter the Burst times..\n");
for(i=0;i<nop;i++)
{
wt[i]=tt[i]=0;
printf("P%d\t: ",i+1); scanf("%d",&b[i]);
rem[i]=b[i];
tbt+=b[i];
flag[i]=0;
}
from=0;
i=0;
printf("\n\t Gantt Chart");
printf("\n ProcessID\tFrom Time\tTo Time\n");
while(from<tbt)
{
if(!flag[i])
{
if(rem[i]<=ts)
{ dur=rem[i]; flag[i]=1; tt[i]=dur+from; wt[i]=tt[i]-b[i];
}
else
dur=ts;
printf("%7d%15d%15d\n",i+1, from,from+dur);
rem[i] -= dur;
from += dur;
}
32
i=(i+1)%nop;
}
for(i=0;i<nop;i++)
{ twt+=wt[i]; ttt+=tt[i];
}
printf("\n\n Process ID \t Waiting Time \t Turn Around Time");
for(i=0;i<nop;i++)
{
printf("\n\t%d\t\t%d\t\t%d",i+1,wt[i],tt[i]);
} awt=(float)twt/(float)nop; att=(float)ttt/(float)nop;
printf("\nTotal Waiting Time:%d",twt); printf("\nTotal Turn Around Time:%d",ttt); printf("\nAverage
Waiting Time:%.2f",awt);
printf("\nAverage Turn Around Time:%.2f\n",att);
}
33
OUTPUT:
[fosslab@fosslab ~]$ vi finallrr.c
[fosslab@fosslab ~]$ cc finallrr.c
[fosslab@fosslab ~]$ ./a.out
Enter no. of Processes: 3
Enter the time slice: 3
Enter the Burst times..
P1 : 24
P2 : 5
P3 : 3
Gantt Chart
ProcessID From Time To Time
1 0 3
2 3 6
3 6 9
1 9 12
2 12 14
1 14 17
1 17 20
1 20 23
1 23 26
1 26 29
1 29 32
34
PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
{
int et[20],at[10],n,i,j,temp,st[10],ft[10],wt[10],ta[10];
int totwt=0,totta=0;
float awt,ata;
char pn[10][10],t[10];
printf("Enter the number of process:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter process name, arrival time & execution time:");
scanf("%s%d%d",pn[i],&at[i],&et[i]);
}
for(i=0;i<n;i++) for(j=0;j<n;j++)
{
if(et[i]<et[j])
{
temp=at[i];
at[i]=at[j];
at[j]=temp;
temp=et[i];
et[i]=et[j];
et[j]=temp;
strcpy(t,pn[i]);
strcpy(pn[i],pn[j]);
strcpy(pn[j],t);
}
}
for(i=0;i<n;i++)
{
if(i==0)
st[i]=at[i];
else
35
st[i]=ft[i-1];
wt[i]=st[i]-at[i];
ft[i]=st[i]+et[i];
ta[i]=ft[i]-at[i];
totwt+=wt[i];
totta+=ta[i];
}
awt=(float)totwt/n;
ata=(float)totta/n;
printf("\nPname\tarrivaltime\texecutiontime\twaitingtime\ttatime");
for(i=0;i<n;i++)
printf("\n%s\t%5d\t\t%5d\t\t%5d\t\t%5d",pn[i],at[i],et[i],wt[i],ta[i]);
printf("\nAverage waiting time is:%f",awt);
printf("\nAverage turnaroundtime is:%f",ata);
}
36
OUTPUT:
[fosslab@fosslab ~]$ vi finalsjf.c
[fosslab@fosslab ~]$ cc finalsjf.c
[fosslab@fosslab ~]$ ./a.out
Enter the number of process: 3
Enter process name, arrival time & execution time: short 4 3
Enter process name, arrival time & execution time: long 5 2
Enter process name, arrival time & execution time: medium 2 5
37
PROGRAM:
#include<stdio.h>
int main()
{
int n,b[10],t=0,i,w=0,r=0,a=0; float avg,avg1;
printf("\nEnter number of processes:");
scanf("%d",&n);
printf("\nEnter the burst times : \n");
for(i=1;i<=n;i++) scanf("%d",&b[i]);
printf("\n Gantt chart ");
for(i=1;i<=n;i++)
printf("P%d\t",i);
printf("\n\nProcess BurstTime WaitingTime TurnaroundTime\n");
for(i=1;i<=n;i++)
{
t=t+w;
r=r+b[i];
printf("P%d\t\t%d\t\t%d\t\t%d\t\t\n",i,b[i],w,r);
w=w+b[i];
a=a+r;
}
avg=(float)t/n;
avg1=(float)a/n;
printf("\n Average WaitingTime is %f",avg);
printf("\n Average TurnaroundTime is %f\n",avg1);
return(0);
}
38
OUTPUT:
[fosslab@fosslab ~]$ vi fcfsfinal.c
[fosslab@fosslab ~]$ cc fcfsfinal.c
[fosslab@fosslab ~]$ ./a.out
Enter number of processes:3
Enter the burst times :
3
5
7
Gantt chart P1 P2 P3
39
PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
{
int et[20],at[10],n,i,j,temp,p[10],st[10],ft[10],wt[10],ta[10];
int totwt=0,totta=0;
float awt,ata;
char pn[10][10],t[10];
printf("Enter the number of process:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter process name,arrivaltime,execution time & priority:");
scanf("%s%d%d%d",pn[i],&at[i],&et[i],&p[i]);
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(p[i]<p[j])
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
temp=at[i];
at[i]=at[j];
at[j]=temp;
temp=et[i];
et[i]=et[j];
et[j]=temp;
strcpy(t,pn[i]);
strcpy(pn[i],pn[j]);
strcpy(pn[j],t);
40
}
}
for(i=0;i<n;i++)
{
if(i==0)
{
st[i]=at[i];
wt[i]=st[i]-at[i];
ft[i]=st[i]+et[i];
ta[i]=ft[i]-at[i];
}
else
{
st[i]=ft[i-1];
wt[i]=st[i]-at[i];
ft[i]=st[i]+et[i];
ta[i]=ft[i]-at[i];
}
totwt+=wt[i];
totta+=ta[i];
}
awt=(float)totwt/n;
ata=(float)totta/n;
printf("\nPname\tarrivaltime\texecutiontime\tpriority\twaitingtime\ttatime");
for(i=0;i<n;i++)
printf("\n%s\t%5d\t\t%5d\t\t%5d\t\t%5d\t\t%5d",pn[i],at[i],et[i],p[i],wt[i],ta[i]);
printf("\n Average waiting time is:%f",awt);
printf("\n Average turnaround time is:%f",ata);
}
41
OUTPUT:
[fosslab@fosslab ~]$ vi finalpriority.c
[fosslab@fosslab ~]$ cc finalpriority.c
[fosslab@fosslab ~]$ ./a.out
Enter the number of process:3
Enter process name,arrivaltime,execution time & priority: long 4 3 2
Enter process name,arrivaltime,execution time & priority: short 1 4 1
Enter process name,arrivaltime,execution time & priority: medium 5 5 4
42
PROGRAM:
#include<stdio.h>
#include<unistd.h>
#include<sys/ipc.h>
#include<sys/uio.h>
#include<sys/types.h>
main()
{
int pid,pfd[2],n,a,b,c;
if(pipe(pfd)==-1)
{
printf("\nError in pipe connection\n");
exit(1);
}
pid=fork();
if(pid>0)
{
printf("\nParent Process");\
printf("\n\n\tFibonacci Series");
else
{
close(pfd[1]);
read(pfd[0],&n,sizeof(n));
printf("\nChild Process");
a=0;
43
b=1;
close(pfd[0]);
c=a+b;
printf("\n%d",c);
a=b;
b=c;
n--;
}
}
}
44
OUTPUT:
Parent Process
Fibonacci Series
Process
0
1
1
2
45
PROGRAM:
#include<stdio.h>
int mutex=1,full=0,empty=3,x=0;
main()
{
int n;
void producer();
void consumer();
int wait(int);
int signal(int);
printf("\n 1.producer\n2.consumer\n3.exit\n");
while(1)
{
printf(" \nenter ur choice");
scanf("%d",&n);
switch(n)
{
case 1:if((mutex==1)&&(empty!=0))
producer();
else
printf("buffer is full\n");
break;
case 2:if((mutex==1)&&(full!=0))
consumer();
else
printf("buffer is empty");
break;
case 3:exit(0);
break;
}
}
}
int wait(int s)
{
return(--s);
}
int signal(int s)
{
return (++s);
}
void producer()
{
mutex=wait(mutex);
full=signal(full);
empty=wait(empty);
46
x++;
printf("\n producer produces the items %d",x);
mutex=signal(mutex);
}
void consumer()
{
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
printf("\n consumer consumes the item %d",x);
x--;
mutex=signal(mutex);
}
47
OUTPUT:
[fosslab@fosslab ~]$ vi finalsemaphore.c
[fosslab@fosslab ~]$ cc finalsemaphore.c
[fosslab@fosslab ~]$ ./a.out
1. producer
2. consumer
3. exit
enter ur choice 1
producer produces the items 1
enter ur choice 2
consumer consumes the item 1
enter ur choice 1
producer produces the items 1
enter ur choice 1
producer produces the items 2
enter ur choice 2
consumer consumes the item 2
enter ur choice 1
producer produces the items 2
enter ur choice 2
consumer consumes the item 2
enter ur choice 2
consumer consumes the item 1
enter ur choice 2
buffer is empty
enter ur choice 1
producer produces the items 1
enter ur choice 3
48
PROGRAM:
#include<stdio.h>
struct da
{
int max[10],a1[10],need[10],before[10],after[10];
}p[10];
void main()
{
int i,j,k,l,r,n,tot[10],av[10],cn=0,cz=0,temp=0,c=0;
printf("\n ENTER THE NO. OF PROCESSES:");
scanf("%d",&n);
printf("\n ENTER THE NO. OF RESOURCES:");
scanf("%d",&r);
for(i=0;i<n;i++)
{
printf("PROCESS %d \n",i+1);
for(j=0;j<r;j++)
{
printf("MAXIMUM VALUE FOR RESOURCE %d:",j+1);
scanf("%d",&p[i].max[j]);
}
for(j=0;j<r;j++)
{
printf("ALLOCATED FROM RESOURCE %d:",j+1);
scanf("%d",&p[i].a1[j]);
p[i].need[j]=p[i].max[j]-p[i].a1[j];
}
}
for(i=0;i<r;i++)
{
printf("ENTER TOTAL VALUE OF RESOURCE %d:",i+1);
scanf("%d",&tot[i]);
}
for(i=0;i<r;i++)
{
for(j=0;j<n;j++)
temp=temp+p[j].a1[i];
av[i]=tot[i]-temp;
temp=0;
}
printf("\n\t RESOURCES ALLOCATED NEEDED TOTAL AVAIL");
for(i=0;i<n;i++)
{
printf("\n P%d \t",i+1);
for(j=0;j<r;j++)
49
printf("%d",p[i].max[j]);
printf("\t");
for(j=0;j<r;j++)
printf("%d",p[i].a1[j]);
printf("\t");
for(j=0;j<r;j++)
printf("%d",p[i].need[j]);
printf("\t");
for(j=0;j<r;j++)
{
if(i==0)
printf("%d",tot[j]);
}
printf(" ");
for(j=0;j<r;j++)
{
if(i==0)
printf("%d",av[j]);
}
}
printf("\n\n\t AVAIL BEFORE\T AVAIL AFTER ");
for(l=0;l<n;l++)
{
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
if(p[i].need[j] >av[j])
cn++;
if(p[i].max[j]==0)
cz++;
}
if(cn==0 && cz!=r)
{
for(j=0;j<r;j++)
{
p[i].before[j]=av[j]-p[i].need[j];
p[i].after[j]=p[i].before[j]+p[i].max[j];
av[j]=p[i].after[j];
p[i].max[j]=0;
}
printf("\n P %d \t",i+1);
for(j=0;j<r;j++)
printf("%d",p[i].before[j]);
printf("\t");
for(j=0;j<r;j++)
printf("%d",p[i].after[j]);
50
cn=0;
cz=0;
c++;
break;
}
else
{
cn=0;cz=0;
}
}
}
if(c==n)
printf("\n THE ABOVE SEQUENCE IS A SAFE SEQUENCE");
else
printf("\n DEADLOCK OCCURED");
}
51
OUTPUT:
//TEST CASE 1:
ENTER THE NO. OF PROCESSES:4
ENTER THE NO. OF RESOURCES:3
PROCESS 1
MAXIMUM VALUE FOR RESOURCE 1:3
MAXIMUM VALUE FOR RESOURCE 2:2
MAXIMUM VALUE FOR RESOURCE 3:2
ALLOCATED FROM RESOURCE 1:1
ALLOCATED FROM RESOURCE 2:0
ALLOCATED FROM RESOURCE 3:0
PROCESS 2
MAXIMUM VALUE FOR RESOURCE 1:6
MAXIMUM VALUE FOR RESOURCE 2:1
MAXIMUM VALUE FOR RESOURCE 3:3
ALLOCATED FROM RESOURCE 1:5
ALLOCATED FROM RESOURCE 2:1
ALLOCATED FROM RESOURCE 3:1
PROCESS 3
MAXIMUM VALUE FOR RESOURCE 1:3
MAXIMUM VALUE FOR RESOURCE 2:1
MAXIMUM VALUE FOR RESOURCE 3:4
ALLOCATED FROM RESOURCE 1:2
ALLOCATED FROM RESOURCE 2:1
ALLOCATED FROM RESOURCE 3:1
PROCESS 4
MAXIMUM VALUE FOR RESOURCE 1:4
MAXIMUM VALUE FOR RESOURCE 2:2
MAXIMUM VALUE FOR RESOURCE 3:2
ALLOCATED FROM RESOURCE 1:0
ALLOCATED FROM RESOURCE 2:0
ALLOCATED FROM RESOURCE 3:2
ENTER TOTAL VALUE OF RESOURCE 1:9
ENTER TOTAL VALUE OF RESOURCE 2:3
ENTER TOTAL VALUE OF RESOURCE 3:6
PROCESS 2
MAXIMUM VALUE FOR RESOURCE 1:6
MAXIMUM VALUE FOR RESOURCE 2:1
MAXIMUM VALUE FOR RESOURCE 3:3
ALLOCATED FROM RESOURCE 1:5
ALLOCATED FROM RESOURCE 2:1
ALLOCATED FROM RESOURCE 3:1
PROCESS 3
MAXIMUM VALUE FOR RESOURCE 1:3
MAXIMUM VALUE FOR RESOURCE 2:1
MAXIMUM VALUE FOR RESOURCE 3:4
ALLOCATED FROM RESOURCE 1:2
ALLOCATED FROM RESOURCE 2:1
ALLOCATED FROM RESOURCE 3:2
PROCESS 4
MAXIMUM VALUE FOR RESOURCE 1:4
MAXIMUM VALUE FOR RESOURCE 2:2
MAXIMUM VALUE FOR RESOURCE 3:2
ALLOCATED FROM RESOURCE 1:0
ALLOCATED FROM RESOURCE 2:0
ALLOCATED FROM RESOURCE 3:2
ENTER TOTAL VALUE OF RESOURCE 1:9
ENTER TOTAL VALUE OF RESOURCE 2:3
ENTER TOTAL VALUE OF RESOURCE 3:6
53
P1 322 101 221 936 110
P2 613 511 102
P3 314 212 102
P4 422 002 420
54
Program:
#include<stdio.h>
#include<conio.h>
int max[100][100];
int alloc[100][100];
int need[100][100];
int avail[100];
int n,r;
void input();
void show();
void cal();
int main()
int i,j;
input();
show();
cal();
getch();
return 0;
void input()
int i,j;
scanf("%d",&n);
scanf("%d",&r);
55
printf("Enter the Max Matrix\n");
for(i=0;i<n;i++)
for(j=0;j<r;j++)
scanf("%d",&max[i][j]);
for(i=0;i<n;i++)
for(j=0;j<r;j++)
scanf("%d",&alloc[i][j]);
for(j=0;j<r;j++)
scanf("%d",&avail[j]);
void show()
int i,j;
for(i=0;i<n;i++)
printf("\nP%d\t ",i+1);
56
for(j=0;j<r;j++)
printf("%d ",alloc[i][j]);
printf("\t");
for(j=0;j<r;j++)
printf("%d ",max[i][j]);
printf("\t");
if(i==0)
for(j=0;j<r;j++)
printf("%d ",avail[j]);
}
void cal()
int finish[100],temp,need[100][100],flag=1,k,c1=0;
int dead[100];
int safe[100];
int i,j;
for(i=0;i<n;i++)
finish[i]=0;
for(i=0;i<n;i++)
{
57
for(j=0;j<r;j++)
need[i][j]=max[i][j]-alloc[i][j];
while(flag)
flag=0;
for(i=0;i<n;i++)
int c=0;
for(j=0;j<r;j++)
if((finish[i]==0)&&(need[i][j]<=avail[j]))
c++;
58
if(c==r)
for(k=0;k<r;k++)
avail[k]+=alloc[i][j];
finish[i]=1;
flag=1;
//printf("\nP%d",i);
if(finish[i]==1)
i=n;
j=0;
flag=0;
for(i=0;i<n;i++)
if(finish[i]==0)
dead[j]=i;
j++;
flag=1;
59
if(flag==1)
for(i=0;i<n;i++)
printf("P%d\t",dead[i]);
else
Output
60
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
void *functionC();
pthread_mutex_t mutex1=PTHREAD_MUTEX_INITIALIZER;
int counter=0;
void main()
{
int rc1,rc2;
pthread_t thread1, thread2;
if((rc1=pthread_create(&thread1,NULL, &functionC,NULL)))
printf("thread creation failesd:%d\n", rc1);
if((rc2=pthread_create(&thread2,NULL,&functionC,NULL)))
pthread_join(thread1, NULL);
pthread_join(thread2,NULL);
exit(EXIT_SUCCESS);
}
void *functionC()
{
pthread_mutex_lock(&mutex1);
counter++;
printf("counter value %d\n", counter);
pthread_mutex_unlock(&mutex1);
61
OUTPUT:
[fosslab@fosslab ~]$ vi mutex1.c
[fosslab@fosslab ~]$ cc -lpthread mutex1.c
[fosslab@fosslab ~]$ ./a.out
counter value 1
counter value 2
62
Program:
#include<stdio.h>
void main()
int memsize=15;
int pagesize,nofpage;
int p[100];
int frameno,offset;
int logadd,phyadd;
int i;
int choice=0;
scanf("%d",&pagesize);
nofpage=memsize/pagesize;
for(i=0;i<nofpage;i++)
scanf("%d",&p[i]);
do
scanf("%d",&logadd);
frameno=logadd/pagesize;
offset=logadd%pagesize;
phyadd=(p[frameno]*pagesize)+offset;
scanf("%d",&choice);
}while(choice==1);
64
OUTPUT:
Your memsize is 15
65
a) WORST-FIT
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
int frag[max],b[max],f[max],i,j,nb,nf,temp;
clrscr();
scanf("%d",&nb);
scanf("%d",&nf);
for(i=1;i<=nb;i++)
printf("Block %d:",i);
scanf("%d",&b[i]);
printf("File %d:",i);
scanf("%d",&f[i]);
for(i=1;i<=nf;i++)
for(j=1;j<=nb;j++)
66
if(bf[j]!=1)
temp=b[j]-f[i];
if(temp>=0)
ff[i]=j;
break;
frag[i]=temp;
bf[ff[i]]=1;
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
67
INPUT
Block 1: 5
Block 2: 2
Block 3: 7
File 1: 1
File 2: 4
OUTPUT
1 1 1 5 4
2 4 3 7 3
68
b) Best-fit
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
clrscr();
scanf("%d",&nb);
scanf("%d",&nf);
for(i=1;i<=nb;i++)
printf("Block %d:",i);
scanf("%d",&b[i]);
for(i=1;i<=nf;i++)
printf("File %d:",i);
scanf("%d",&f[i]);
for(i=1;i<=nf;i++)
69
for(j=1;j<=nb;j++)
if(bf[j]!=1)
temp=b[j]-f[i];
if(temp>=0)
if(lowest>temp)
ff[i]=j;
lowest=temp;
}
}
frag[i]=lowest;
bf[ff[i]]=1;
lowest=10000;
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
70
INPUT
Block 1: 5
Block 2: 2
Block 3: 7
File 1: 1
File 2: 4
OUTPUT
1 1 2 2 1
2 4 1 5 1
71
c) First-fit
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
clrscr();
scanf("%d",&nb);
scanf("%d",&nf);
for(i=1;i<=nb;i++)
printf("Block %d:",i);
scanf("%d",&b[i]);
for(i=1;i<=nf;i++)
printf("File %d:",i);
scanf("%d",&f[i]);
for(i=1;i<=nf;i++)
72
{
for(j=1;j<=nb;j++)
temp=b[j]-f[i];
if(temp>=0)
if(highest<temp)
ff[i]=j;
highest=temp;
frag[i]=highest;
bf[ff[i]]=1;
highest=0;
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
73
INPUT
Block 1: 5
Block 2: 2
Block 3: 7
File 1: 1
File 2: 4
OUTPUT
1 1 3 7 6
2 4 1 5 1
74
PROGRAM:
#include<stdio.h>
void main()
{
int a[5],b[20],n,p=0,q=0,m=0,h,k,i,q1=1;
char f='F';
scanf("%d",&b[i]);
for(i=0;i<n;i++)
{if(p==0)
{
if(q>=3)
q=0;
a[q]=b[i];
q++;
if(q1<3)
{
q1=q;
}
}
printf("\n%d",b[i]);
printf("\t");
for(h=0;h<q1;h++)
printf("%d",a[h]);
if((p==0)&&(q<=3))
{
printf("-->%c",f);
m++;
}
75
p=0;
for(k=0;k<q1;k++)
{
if(b[i+1]==a[k])
p=1;
}
}
printf("\nNo of faults:%d",m);
76
OUTPUT:
Input:
Enter the Number of Pages: 12
Enter 12 Page Numbers:
232152453252
22-->F
323-->F
223
1231-->F
5531-->F
2521-->F
4524-->F
5524
3324-->F
2324
5354-->F
2352-->F
No of faults:9
77
PROGRAM:
#include<stdio.h>
void main()
{
int g=0,a[5],b[20],p=0,q=0,m=0,h,k,i,q1=1,j,u,n;
char f='F';
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
{if(p==0)
{
if(q>=3)
q=0;
a[q]=b[i];
q++;
if(q1<3)
{
q1=q;
g=1;
}}
printf("\n%d",b[i]);
printf("\t");
for(h=0;h<q1;h++)
printf("%d",a[h]);
if((p==0)&&(q<=3))
{
printf("-->%c",f);
78
m++;
}
p=0;
g=0;
if(q1==3)
{
for(k=0;k<q1;k++)
{
if(b[i+1]==a[k])
p=1;
}
for(j=0;j<q1;j++)
u=0;
k=i;
while(k>=(i-1)&&(k>=0))
{
if(b[k]==a[j])
u++;
k--;
}
if(u==0)
q=j;
}}
else
{
for(k=0;k<q;k++)
{
if(b[i+1]==a[k])
p=1;
}}}
printf("\nNo of faults:%d",m);}
79
OUTPUT:
No of faults:9[fosslab@fosslab ~]$ vi finaslru.c
[fosslab@fosslab ~]$ cc finaslru.c
[fosslab@fosslab ~]$ ./a.out
22-->F
323-->F
223
1231-->F
5251-->F
2251
4254-->F
5254
3354-->F
2352-->F
5352
2352
No of faults:7
80
PROGRAM:
#include<stdio.h>
#include<conio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
int recent[10],optcal[50],count=0;
int optvictim();
void main()
clrscr();
printf("\n................................ ");
scanf("%d",&nof);
scanf("%d",&nor);
for(i=0;i<nor;i++)
scanf("%d",&ref[i]);
clrscr();
printf("\n............................... ");
printf("\n................... \n");
for(i=0;i<nor;i++)
printf("%4d",ref[i]);
for(i=0;i<nof;i++)
frm[i]=-1;
81
optcal[i]=0;
for(i=0;i<10;i++)
recent[i]=0;
printf("\n");
for(i=0;i<nor;i++)
flag=0;
printf("\n\tref no %d ->\t",ref[i]);
for(j=0;j<nof;j++)
if(frm[j]==ref[i])
flag=1;
break;
if(flag==0)
count++;
if(count<=nof)
victim++;
else
victim=optvictim(i);
pf++;
frm[victim]=ref[i];
for(j=0;j<nof;j++)
printf("%4d",frm[j]);
}
82
printf("\n Number of page faults: %d",pf);
getch();
int i,j,temp,notfound;
for(i=0;i<nof;i++)
notfound=1;
for(j=index;j<nor;j++)
if(frm[i]==ref[j])
notfound=0;
optcal[i]=j;
break;
if(notfound==1)
return i;
}
temp=optcal[0];
for(i=1;i<nof;i++)
if(temp<optcal[i])
temp=optcal[i];
for(i=0;i<nof;i++)
if(frm[temp]==frm[i])
return i;
return 0;
83
OUTPUT:
654231
…………………. 6 5 4 2 3 1
Reference NO 6-> 6 -1 -1
Reference NO 5-> 6 5 -1
Reference NO 4-> 6 5 4
Reference NO 2-> 2 5 4
Reference NO 3-> 2 3 4
Reference NO 1-> 2 3 1
84
PROGRAM:
#include<stdio.h>
main()
{
int master,s[20];
char f[20][20][20];
char d[20][20];
int i,j;
printf(" directory\tsize\tfilenames\n");
printf("*************************************************\n");
for(i=0;i<master;i++)
{
printf("%s\t\t%2d\t",d[i],s[i]);
for(j=0;j<s[i];j++)
printf("%s\n\t\t\t",f[i][j]);
printf("\n");
}
printf("\t\n");}
85
OUTPUT:
[fosslab@fosslab ~]$ cc Finalsinglelevel.c
long 3 we
er
ty
86
PROGRAM:
#include<stdio.h>
struct st
{
char dname[10];
char sdname[10][10];
char fname[10][10][10];
int ds,sds[10];
}dir[10];
void main()
{
int i,j,k,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter directory %d names:",i+1);
scanf("%s",&dir[i].dname);
printf("enter size of directories:");
scanf("%d",&dir[i].ds);
for(j=0;j<dir[i].ds;j++)
{
{
printf("%s\t\t%d",dir[i].dname,dir[i].ds);
for(j=0;j<dir[i].ds;j++)
{
printf("\t%s\t\t%d\t",dir[i].sdname[j],dir[i].sds[j]);
for(k=0;k<dir[i].sds[j];k++)
printf("%s\t",dir[i].fname[j][k]);
printf("\n\t\t");
}
printf("\n");
}
}
88
OUTPUT:
[fosslab@fosslab ~]$ ./a.out
enter number of directories: 2
******************************************************
short 1tooshort 1a
long 1toolong 1 aaaaaaa
89
PROGRAM:
# include<stdio.h>
# include<graphics.h>
struct tree_element
{
char name[20];
int x,y,ftype,lx,rx,nc,level;
struct tree_element*link[5];
};
typedef struct tree_element node;
void main( )
{
int gd=DETECT,gm;node*root;
root=NULL;
clrscr( );
create(&root,0,"root",0,639,320);
clrscr();
initgraph(&gd,&gm,"c:\\tc\\BGI");
display(root);getch();closegraph();
}
create(node**root,int lev, char * dname, int lx , int rx, int x)
{
int i,gap;
if(*root==NULL)
{
(*root)=(node*)malloc(sizeof(node));
printf("Enter name of dir/file(under%s):",dname);
fflush(stdin);
gets((*root)->name);
printf("enter 1 for Dir / 2 for file :");
scanf("%d",&(*root)->ftype);
(*root)->level=lev;
(*root)->y=50+lev*50;
(*root)->x=x;(*root)->lx=lx;(*root)->rx=rx;
for(i=0;i<5;i++)
(*root)->link[i]=NULL;
90
if((*root)->ftype==1)
{
printf("No of sub directories/files(for%s):",(*root)->name);
scanf("%d",&(*root)->nc);
if((*root)->nc==0)gap=rx-lx;
else
gap=(rx-lx)/(*root)->nc;
for(i=0;i<(*root)->nc;i++)
create(&((*root)->link[i]),lev+1,(*root)->name,lx+gap*i,lx+gap*i+gap,lx+gap*i+gap/2);
}
else(*root)->nc=0;
}
}
display(node*root)
{
int i;
settextstyle(2,0,4);settextjustify(1,1);setfillstyle(1,BLUE);setcolor(14);
if( root!=NULL)
{
for(i=0;i<root->nc;i++)
{
line(root->x,root->y,root->link[i]->x,root->link[i]->y);
}
if(root->ftype==1)bar3d(root->x-20,root->y-10,root->x+20,root->y+10,0,0);
elsefillellipse(root->x,root->y,20,20);
outtextxy(root->x,root->y,root->name);
for(i=0;i<root->nc;i++)
{
display(root->link[i]);
}}}
91
OUTPUT:
92
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<string.h>
struct tree_element
{
char name[20];
int x,y,ftype,lx,rx,nc,level;
struct tree_element *link[5];
};
void main()
{
int gd=DETECT,gm;
root=NULL;
clrscr();
create(&root,0,"root",0,639,320);
read_links();
clrscr();
initgraph(&gd,&gm,"C:\\TC\\BGI");
draw_link_lines();
display(root);
getch();
closegraph();
}
read_links()
{
int i;
printf("how many links");
scanf("%d",&nofl);
for(i=0;i<nofl;i++)
{
printf("File/dir:");
93
fflush(stdin);
gets(L[i].from);
printf("user name:");
fflush(stdin);
gets(L[i].to);
}
}
draw_link_lines()
{
int i,x1,y1,x2,y2;
for(i=0;i<nofl;i++)
{
search(root,L[i].from,&x1,&y1);
search(root,L[i].to,&x2,&y2);
setcolor(LIGHTGREEN);
setlinestyle(3,0,1);
line(x1,y1,x2,y2);
setcolor(YELLOW);
setlinestyle(0,0,1);
}
}
search(node *root,char *s,int *x,int *y)
{
int i;
if(root!=NULL)
{
if(strcmpi(root->name,s)==0)
{
*x=root->x;
*y=root->y;
return;
}
else
{
for(i=0;i<root->nc;i++)
search(root->link[i],s,x,y);
}
}
}
create(node **root,int lev,char *dname,int lx,int rx,int x)
{
int i,gap;
if(*root==NULL)
{
(*root)=(node *)malloc(sizeof(node));
printf("enter name of dir/file(under %s):",dname);
fflush(stdin);
94
gets((*root)->name);
printf("enter 1 for dir/ 2 for file:");
scanf("%d",&(*root)->ftype);
(*root)->level=lev;
(*root)->y=50+lev*50;
(*root)->x=x;
(*root)->lx=lx;
(*root)->rx=rx;
for(i=0;i<5;i++)
(*root)->link[i]=NULL;
if((*root)->ftype==1)
{
printf("no of sub directories /files (for %s):",(*root)->name);
scanf("%d",&(*root)->nc);
if((*root)->nc==0)
gap=rx-lx;
else
gap=(rx-lx)/(*root)->nc;
for(i=0;i<(*root)->nc;i++)
create( & ( (*root)->link[i] ) , lev+1 ,
(*root)->name,lx+gap*i,lx+gap*i+gap,lx+gap*i+gap/2);
}
else (*root)->nc=0;
}
}
/* displays the constructed tree in graphics
mode */ display(node *root)
{
int i;
settextstyle(2,0,4);
settextjustify(1,1);
setfillstyle(1,BLUE);
setcolor(14); if(root
!=NULL)
{
for(i=0;i<root->nc;i++)
{
line(root->x,root->y,root->link[i]->x,root->link[i]->y);
}
if(root->ftype==1) bar3d(root->x-20,root->y-10,root->x+20,root->y+10,0,0);
else
fillellipse(root->x,root->y,20,20);
outtextxy(root->x,root->y,root->name); for(i=0;i<root->nc;i++)
{
display(root->link[i]);
}}}
95
OUTPUT:
Output:
96
PROGRAM:
#include<stdio.h>
main()
{
int f[50],i,st,j,len,c,k;
for(i=0;i<50;i++)
f[i]=0;
X:
printf("\n Enter the starting block & length of file");
scanf("%d%d",&st,&len);
for(j=st;j<(st+len);j++)
if(f[j]==0)
{
f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("Block already allocated");
break;
}
if(j==(st+len))
printf("\n the file is allocated to disk");
printf("\n if u want to enter more files?(y-1/n-0)");
scanf("%d",&c);
if(c==1)
goto X;
}
97
OUTPUT:
[fosslab@fosslab ~]$ vi finalseq.c
9->1
10->1
11->1
12->1
13->1
the file is allocated to disk
98
PROGRAM:
#include<stdio.h>
void main()
{
char a[10];
inti,ib,cib[10];
printf("\n enter the filename:");
scanf("%s",a);
printf("\n indexblock:"); scanf("%d",&ib); for(i=1;i<=5;i++)
{
scanf("%d",&cib[i]);
}
printf("\n the list of files\t indexblock\n");
printf("%s\t\t %d",a,ib);
printf("\n");
for(i=1;i<=5;i++)
{
printf("%d\t\t",cib[i]);
}
printf("\n");
}
99
OUTPUT:
[fosslab@fosslab ~]$ vi finalindex.c
[fosslab@fosslab ~]$ cc finalindex.c
[fosslab@fosslab ~]$ ./a.out
100
PROGRAM:
#include<stdio.h>
void main()
{
char a[10];
inti,sb,eb,fb1[10];
scanf("%s",a);
printf("\n Enter the starting block:");
scanf("%d",&sb);
printf("Enter the ending Block:");
scanf("%d",&eb);
for(i=0;i<5;i++)
{
101
OUTPUT:
[fosslab@fosslab ~]$ vi finallinked.c
[fosslab@fosslab ~]$ cc finallinked.c
[fosslab@fosslab ~]$ ./a.out
enter the file name: testing
18->11->45->17->34->15->26
102
C-Program of FCFS (First come first serve) Disk scheduling Algorithms
#include<stdio.h>
#include<stdlib.h>
int main()
int RQ[100],i,n,TotalHeadMoment=0,initial;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
scanf("%d",&initial);
for(i=0;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
return 0;
103
Output:-
50
104
SSTF (Short seek time first )Disk scheduling Algorithms
#include<stdio.h>
#include<stdlib.h>
int main()
int RQ[100],i,n,TotalHeadMoment=0,initial,count=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
scanf("%d",&initial);
while(count!=n)
int min=1000,d,index;
for(i=0;i<n;i++)
d=abs(RQ[i]-initial);
if(min>d)
min=d;
index=i;
105
}
TotalHeadMoment=TotalHeadMoment+min;
initial=RQ[index];
RQ[index]=1000;
count++;
return 0;
106
Output:-
50
107
C-program of scan or elevator disk scheduling
#include<stdio.h>
#include<stdlib.h>
int main()
int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
scanf("%d",&initial);
scanf("%d",&size);
printf("Enter the head movement direction for high 1 and for low 0\n");
scanf("%d",&move);
for(i=0;i<n;i++)
for(j=0;j<n-i-1;j++)
if(RQ[j]>RQ[j+1])
108
int temp;
temp=RQ[j]; RQ[j]=RQ[j+1];
RQ[j+1]=temp;
int index;
for(i=0;i<n;i++)
if(initial<RQ[i])
index=i;
break;
if(move==1)
for(i=index;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
TotalHeadMoment=TotalHeadMoment+abs(size-RQ[i-1]-1);
initial = size-1;
109
for(i=index-1;i>=0;i--)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
else
for(i=index-1;i>=0;i--)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
TotalHeadMoment=TotalHeadMoment+abs(RQ[i+1]-0);
initial =0;
for(i=index;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
return 0;
110
Output:-
50
200
Enter the head movement direction for high 1 and for low 0
111
C program for C-SCAN disk Scheduling algorithm
#include<stdio.h>
#include<stdlib.h>
int main()
int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
scanf("%d",&initial);
scanf("%d",&size);
printf("Enter the head movement direction for high 1 and for low 0\n");
scanf("%d",&move);
for(i=0;i<n;i++)
for( j=0;j<n-i-1;j++)
if(RQ[j]>RQ[j+1])
int temp;
temp=RQ[j];
112
RQ[j]=RQ[j+1];
RQ[j+1]=temp;
int index;
for(i=0;i<n;i++)
if(initial<RQ[i])
index=i;
break;
}
// if movement is towards high value
if(move==1)
for(i=index;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
TotalHeadMoment=TotalHeadMoment+abs(size-RQ[i-1]-1);
TotalHeadMoment=TotalHeadMoment+abs(size-1-0);
initial=0;
for( i=0;i<index;i++)
113
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
else
for(i=index-1;i>=0;i--)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
// last movement for min size
TotalHeadMoment=TotalHeadMoment+abs(RQ[i+1]-0);
TotalHeadMoment=TotalHeadMoment+abs(size-1-0);
initial =size-1;
for(i=n-1;i>=index;i--)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
return 0;
}
114
Output:-
50
200
Enter the head movement direction for high 1 and for low 0
115
C- program of look disk scheduling in operating system
#include<stdio.h>
#include<stdlib.h>
int main()
int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
scanf("%d",&initial);
scanf("%d",&size);
printf("Enter the head movement direction for high 1 and for low 0\n");
scanf("%d",&move);
for(i=0;i<n;i++)
for(j=0;j<n-i-1;j++)
if(RQ[j]>RQ[j+1])
{
int temp;
temp=RQ[j];
116
RQ[j]=RQ[j+1];
RQ[j+1]=temp;
int index;
for(i=0;i<n;i++)
if(initial<RQ[i])
index=i;
break;
if(move==1)
for(i=index;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
for(i=index-1;i>=0;i--)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
117
}
else
for(i=index-1;i>=0;i--)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
for(i=index;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
return 0;
Output:-
118
Enter the number of Request
50
Enter the head movement direction for high 1 and for low 0
119
C-Program of C- Look Disk scheduling Algorithms
#include<stdio.h>
#include<stdlib.h>
int main()
int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
scanf("%d",&initial);
scanf("%d",&size);
printf("Enter the head movement direction for high 1 and for low 0\n");
scanf("%d",&move);
for(i=0;i<n;i++)
{
for( j=0;j<n-i-1;j++)
if(RQ[j]>RQ[j+1])
int temp;
temp=RQ[j];
120
RQ[j]=RQ[j+1];
RQ[j+1]=temp;
int index;
for(i=0;i<n;i++)
if(initial<RQ[i])
index=i;
break;
if(move==1)
for(i=index;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
for( i=0;i<index;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
121
}
else
for(i=index-1;i>=0;i--)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
for(i=n-1;i>=index;i--)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
return 0;
122
Output:-
50
Enter the head movement direction for high 1 and for low 0
123
Ex.No:16. Install any guest operating system like Linux using VMware.
Save the ISO image file in any location accessible to your host. For example:
Note: For best performance, place this image on the host computer's hard drive. However, to make the
ISO image accessible to multiple users, you can also place the ISO image on a network share drive
(Windows) or exported filesystem (Linux). If your OS install spans multiple discs, you need to use an ISO
image of each disc and place them all of them in a location accessible to the host.
Create a new virtual machine. Go to File > New > Virtual Machine.
Select Typical to accept Workstation's recommendations for various settings (such as processors, RAM,
and disk controller type). Select Custom if you want to select these options yourself.
On the Guest Operating System Installation screen, when prompted where to install from, select Installer
disc image file (iso).
Click Browse, and navigate to the location where you saved the ISO image file.
Click Next, and proceed through the new virtual machine wizard.
Before you click Finish, to create the virtual machine, deselect Power on this virtual machine after
creation.
Edit the virtual machine settings so that its virtual CD/DVD device is configured to use the ISO image
rather than the physical CD/DVD drive:
Select the tab for the virtual machine you just created.
Click Browse and navigate to where you saved the ISO image file.
Click OK.
124
Power on the virtual machine.
The virtual machine boots from the ISO image, which contains the installation software for your guest OS.
Follow the installation procedure for your guest OS. For more information, see the Guest Operating
System Installation Guide.
Note: If the guest OS asks for the second CD/DVD, repeat step 8 to point the virtual CD/DVD device to
the second ISO image.
When you are finished installing the guest OS, you can edit the virtual machine settings so that it is once
more set to use the host computer's physical drive. You do not need to leave the drive set to connect at
power on.
Prerequisites
Verify that the operating system is supported. See the online VMware Compatibility Guide on the
VMware Web site.
See the VMware Guest Operating System Installation Guide for information on the guest operating system
that you are installing.
Procedure
If you are installing the guest operating system from an installer disc, configure the virtual machine to use
a physical CD-ROM or DVD drive and configure the drive to connect at power on.
(Remote virtual machine only) Select the location of the CD-ROM or DVD drive.
If you are installing the guest operating system from an ISO image file, configure the CD/DVD drive in
the virtual machine to point to the ISO image file and configure the drive to connect at power on.
(Remote virtual machine only) Select the location of the ISO image file.
Select Use ISO image file and browse to the location of the ISO image file.
If you are installing the guest operating system from an installer disc, insert the disc in the CD-ROM or
DVD drive.
125
Power on the virtual machine.
If the operating system consists of multiple installer discs and you are prompted to insert the next disc,
insert the next disc in the physical drive.
If the operating system consists of multiple ISO image files, select the image file for the next CD.
Select VM > Removable Devices > CD/DVD > Disconnect and disconnect from the current ISO
image file.
Select VM > Removable Devices > CD/DVD > Settings and select the next ISO image file.
Use the standard tools in the operating system to configure its settings.
126
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<fcntl.h>
int main()
int fp1,fp2,o,i;
char *c;
c=(char*)calloc(50,sizeof(char));
fp1=open("input.txt",O_RDONLY);
fp2=open("output.txt",O_CREAT|O_WRONLY|O_TRUNC);
o=read(fp1,c,20);
i=write(fp2,c,strlen(c));
close(fp1);
close(fp2);
127
INPUT FILE: input.txt
Operating systems
OUTPUT:
[student@localhost os]$
Operating systems
128
PROGRAM:
#include<stdio.h>
#include<unistd.h>
#include<sys/ipc.h>
#include<sys/uio.h>
#include<sys/types.h>
main()
int pid,pfd[2],n,a,b,c;
if(pipe(pfd)==-1)
exit(1);
pid=fork();
if(pid>0)
{
printf("\nParent Process");\
printf("\n\n\tFibonacci Series");
scanf("%d",&n);
close(pfd[0]);
write(pfd[1],&n,sizeof(n));
close(pfd[1]);
exit(0);
else
close(pfd[1]);
read(pfd[0],&n,sizeof(n));
129
printf("\nChild Process");
a=0;
b=1;
close(pfd[0]);
printf("\n\n%d\n%d",a,b);
while(n>2)
c=a+b;
printf("\n%d",c);
a=b;
b=c;
n--;
130
OUTPUT:
Parent Process
Fibonacci Series
Child Process
131