Professional Documents
Culture Documents
Aim:
To study the basic commands in Linux.
Commands:
1. TASK
COMMAND
SYNTAX
EXPLANATION
OUTPUT
2. TASK
COMMAND
SYNTAX
EXPLANATION
OUTPUT
3. TASK
COMMAND
SYNTAX
EXPLANATION
OUTPUT
4. TASK
COMMAND
SYNTAX
EXPLANATION
OUTPUT
5. TASK
COMMAND
SYNTAX
EXPLANATION
OUTPUT
6. TASK
COMMAND
SYNTAX
EXPLANATION
OUTPUT
7. TASK
COMMAND
SYNTAX
EXPLANATION
OUTPUT
8. TASK
COMMAND
SYNTAX
EXPLANATION
OUTPUT
9. TASK
COMMAND
SYNTAX
EXPLANATION
OUTPUT
10.TASK
COMMAND
SYNTAX
EXPLANATION
OUTPUT
11. TASK
COMMAND
SYNTAX
EXPLANATION
OUTPUT
12. TASK
COMMAND
SYNTAX
EXPLANATION
OUTPUT
13. TASK
COMMAND
SYNTAX
EXPLANATION
EXAMPLE
OUTPUT
14. TASK
COMMAND
SYNTAX
EXPLANATION
EXAMPLE
OUTPUT
15. TASK
COMMAND
SYNTAX
EXPLANATION
EXAMPLE
OUTPUT
: To delete a directory.
: remove directory.
: rmdir directory name
: This command is used to delete the specified directory.
: rmdir student.
: The student directory is deleted.
16. TASK
COMMAND
SYNTAX
EXPLANATION
17. TASK
COMMAND
SYNTAX
EXPLANATION
18. TASK
COMMAND
SYNTAX
EXPLANATION
: To create a file.
: cat.
: cat> file name.
: This command leads to the creation of a new file with the specifie
file name and contents.
: cat> wind.
: A null file called wind is created.
EXAMPLE
OUTPUT
19. TASK
COMMAND
SYNTAX
EXPLANATION
EXAMPLE
OUTPUT
: To view a file.
: cat.
: cat file name.
: This command displays the contents of the specified file.
: cat wind.
: Contents of the file called wind will be displayed on the screen.
20. TASK
COMMAND
SYNTAX
EXPLANATION
: To copy a file.
: copy.
: cp sourcefile destinationfile.
: This command produces a copy of the source file and is stored in
the specified destination file by overwriting its previous contents.
: cp sun moon.
: The contents of sun file will be copied to the moon file.
EXAMPLE
OUTPUT
21. TASK
COMMAND
SYNTAX
EXPLANATION
EXAMPLE
OUTPUT
22. TASK
COMMAND
SYNTAX
EXPLANATION
EXAMPLE
OUTPUT
: To move a file.
: move.
: mv sourcefile destinationfile.
: After moving the contents of the source file into destination
file the source file is deleted.
: mv sun moon.
: After copying contents from the sun file to moon file, the
sun file is deleted.
: To display / cut a column from a file.
: cut.
: cut c no. file name.
: This command displays the characters of a particular column in the
specified file.
: cut c3 moon.
: Those characters occurring in the 3rd column of the file called
moon are displayed.
23. TASK
COMMAND
SYNTAX
EXPLANATION
EXAMPLE
OUTPUT
: To delete a file.
: remove.
: rm file name.
: This command deletes the specified file from the directory.
: rm sun.
: The file called sun will be deleted.
24. TASK
COMMAND
SYNTAX
EXPLANATION
EXAMPLE
OUTPUT
25. TASK
COMMAND
SYNTAX
EXPLANATION
: To retrieve a file.
: tail.
: tail -no. of rows file name.
: This command displays the specified no. of rows form the bottom
of the specified file.
: tail -1 moon.
: The last row of the file called moon is displayed.
EXAMPLE
OUTPUT
26. TASK
COMMAND
SYNTAX
EXPLANATION
EXAMPLE
OUTPUT
27. TASK
COMMAND
SYNTAX
EXPLANATIO
EXAMPLE
OUTPUT
28. TASK
COMMAND
SYNTAX
EXPLANATION
EXAMPLE
OUTPUT
SHELL PROGRAMMING
Aim:
A Linux shell is a command language interpreter, the primary purpose of which is
to translate the command lines typed at the terminal into system actions. The shell itself is a
program, through which other programs are invoked
A shell script is a file containing a list of commands to be executed by the Linux shell.
shell script provides the ability to create your own customized Linux commands
Linux shell have sophisticated programming capabilities which makes shell script
powerful Linux tools
Program:
echo Enter the value of n:
read n
i=1
sum=0
while [$i le $n]
do
sum=expr $sum + $i
i=expr $i + i
done
avg=expr $sum / $n
echo Sum=$sum
echp Average=$avg
Output:
Enter the value of n: 4
Sum=10
Average=2
FACTORIAL OF A NUMBER
Program:
echo Enter value to find the factorial
read n
i=1
fact=1
while [$i le $n]
do
fact=expr $fact /* $i
i=expr $i + 1
done
echo Factorial=$fact
Output:
Enter value to find the factorial 5
Factorial=120
FIBONNACI SERIES
Program:
echo Enter the n value
read n
i=2
a=0
b=1
echo $a
echo $b
while [$i le $n]
echo $c
a=$b
b=$c
i=expr $i + 1
done
Output:
Enter the n value :2
0
1
1
Output:
Enter the value: 45
The given number is odd
STRING COMPARISON
Program:
echo Enter the Strings
read str1
read str2
if [ $str1 = $str2 ]
then
echo Strings are Equal
else
echo Strings are Not Equal
fi
Output:
Enter the strings:Read In
Read Out
Strings are not equal
Enter the strings: Salai
Salai
Strings are equal
Output:
Enter the string: baba
Length of the string is=4
ARMSTRONG NUMBER
Program:
Echo enter the number
Read num
X=$num
Sum=0
While [ $num gt 0 ]
do
y=expr $num % 10`
z=`expr $y \* $y /* $y`
sum=`expr $sum + $z`
num=`expr $num / 10`
done
if [ $x eq $num ]
then
echo$x is an Armstrong number
else
echo$x is not an Armstrong number
fi
Output:
Enter the number : 979
979 is an Armstrong number
Output:
Enter the value of x: 4
Enter the value of n: 2
The value 4 power 2 is 16
REVERSE STRING
Program:
Output:
Enter a string: Data
Reversed string=atad
Read r
Len=`echo $str | wc c`
Len=expr $len -1`
Count=0
I=1
While [ $i le $len ]
Do
Temp=`echo $str | cut c $i`
If [ $temp = $c ]
Then
New =`echo $new$r`
Else
New=`echo $new$temp`
Fi
I=`expr $i + 1`
Done
Echo the old string is $str
Echothe new string is $new
Output:
Enter the string :nut
Enter the character to be changed : n
Enter the character to be replaced : b
The old string is nut
The new string is but
C PROGRAM
CPU SCHEDULING
Aim:
To write a program to implement the FCFS scheduling algorithm
Algorithm:
1. Start the process
2. Declare the array size
3. Get the number of processes to be inserted
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int nop,i,bt[10],wt[10],tat[10],ttat,twt;
float awt,atat;
clrscr();
awt=0.0;
atat=0.0;
printf("\n\t FCFS sceduling\n");
printf("\n\t Enter the no.of process:");
scanf("%d",&nop);
printf("\n\t Enter the cpu burst time");
for(i=0;i<nop;i++)
scanf("%d",&bt[i]);
wt[0]=0;
tat[0]=bt[0];
twt=wt[0];
ttat=tat[0];
for(i=1;i<nop;i++)
{
wt[i]=wt[i-1]+bt[i-1];
tat[i]=wt[i]+bt[i];
twt=twt+wt[i];
ttat=ttat+tat[i];
}
awt=twt/nop;
atat=ttat/nop;
printf("\n\t process id \t burst time \t waiting time \t turn around time \n");
for(i=0;i<nop;i++)
{
printf("\n\t%d\t\t%d\t\t%d\t\t%d\n",i,bt[i],wt[i],tat[i]);
}
printf("\n the avg wt :%f",awt);
printf("\n theatat:%f",atat);
getch();
}
Output:
FCFS sceduling
Enter the no.of process:3
Enter the cpu burst time10
20
30
process id
burst time
waiting time
10
10
20
10
30
30
30
60
Result:
Thus the program for FCFS is implemented and verified.
Aim:
To implement the shortest job first scheduling algorithm
Algorithm:
1. Start the process
2. Declare the array size
3. Get the number of elements to be inserted
4. Select the process which have shortest burst will execute first
5. If two process have same burst length then FCFS scheduling algorithm used
6. Make the average waiting the length of next process
7. Start with the first process from its selection as above and let other process to be
in queue
8. Calculate the total number of burst time
9. Display the values
10. Stop the process
Program:
#include<stdio.h>
int main()
{
int n,j,temp,temp1,temp2,pr[10],b[10],t[10],w[10],p[10],i;
float att=0,awt=0;
for(i=0;i<10;i++)
{
b[i]=0;w[i]=0;
}
printf("enter the number of process");
scanf("%d",&n);
{
t[i]=w[i]+b[i];
awt=awt+w[i];
att=att+t[i];
}
awt=awt/n;
att=att/n;
printf("\n\t process \t waiting time \t turn around time \n");
for(i=0;i<n;i++)
printf("\t p[%d] \t %d \t\t %d \n",p[i],w[i],t[i]);
printf("the average waitingtimeis %f\n",awt);
printf("the average turn around time is %f\n",att);
return 1;
}
Output:
enter the number of process 5
enter the burst times
2 4 5 6 8
process
waiting time
p[0]
p[1]
p[2]
11
p[3]
11
17
p[4]
17
25
Result :
The program for SJF was implemented and hence verified
Algorithm :
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU
burst time
Step 4: Sort the ready queue according to the priority number.
Step 5: Set the waiting of the first process as 0 and its burst time as its turn around
time
Step 6: For each process in the Ready Q calculate
(a) Waiting time for process(n)= waiting time of process (n-1) + Burst time of
process(n-1)
(b) Turn around time for Process(n)= waiting time of Process(n)+ Burst time
for process(n)
Step 7: Calculate
(a) Average waiting time = Total waiting Time / Number of process
(b) Average Turnaround time = Total Turnaround Time / Number of process
Step 8: Stop the process
Program:
#include<stdio.h>
main()
{
int i,j,n,tp,t,p[20],pr[20],tot=0;
printf("Enter the no of process:");
scanf("%d",&n);
printf("\nEnter the %d Process:");
for(i=0;i<=n;i++)
scanf("%d",&p[i]);
printf("\nEnter %d Priority from %d:");
for(i=0;i<n;i++)
scanf("%d",&pr[i]);
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(pr[i]>pr[j])
{
tp=pr[i];
t=p[i];
pr[i]=pr[j];
p[i]=p[j];
pr[j]=tp;
p[j]=t;
}
c[0]=0;
for(i=0;i<n-1;i++)
c[i+1]=c[i]+p[i];
printf("\nSNO\t
PROCESS\tWAITING TIME\tPRIORITY\n");
for(i=0;i<n;i++)
{
printf(""\n\t%d\t%d\t%d",i+1,p[i],c[i],pr[i]);
tot=tot+c[i];
}
printf("\n Average Waiting time is:%f",((float)tot/n));
}
Output:
ENTER THE NO OF PROCESS : 4
ENTER THE 1 PROCESS :2
ENTER THE 2 PROCESS :1
ENTER THE 3 PROCESS :3
ENTER THE 4 PROCESS :1
ENTER 4 PRIORITY FROM:
6
7
8
7
SNO
1
2
3
4
PROCESS
3
1
1
2
WAITING TIME
0
3
4
5
PRIORITY
8
7
7
6
Result:
The program is hence verified
Algorithm:
1. Start the process
Program:
#include<stdio.h>
main()
{
int p[10][12];
int i,j,a,w=0,n,tq,count=0;
printf("how many process:\t");
scanf("%d",&n);
printf("\n\n process \t burst time\n");
for(i=1;i<=n;i++)
{
p[i][1]=i;
printf("\n \t p%d",p[i][1]);
printf("\t\t");
scanf("%d",&p[i][2]);
}
printf("\n");
printf("\n enter the time quantum:");
scanf("%d",&tq);
printf("\n");
printf("..........\t");
printf("\n\t process \t burst time \t waiting time \n");
printf(".......\t");
while(count<n)
{
for(i=1;i<=n;i++)
{
if(p[i][2]<tq)
a=p[i][2];
else
a=tq;
p[i][2]=-a;
printf("\n\t\t %d\t\t %d\t\t%d\n",p[i][1],a,w);
w=w+a;
count ++;
}
}
}
Output:
how many process:
process
3
burst time
p1
p2
p3
burst time
waiting time
Result:
The program for round robin scheduling was implemented and hence verified
MEMORY MANAGEMENT
SCHEME-I
Algorithm:
Program:
#include<stdio.h>
int main()
{
int a,b[50],i,j;
int temp,s;
printf("\n========BEST FIT==========");
printf("\nenter the number of unallocated spaces:");
scanf("%d",&a);
printf("\n enter the unallocated space in KB:");
for(i=1;i<=a;i++)
for(i=j+1;j<=a;j++)
if(b[i]>b[j])
{
temp=b[j];
b[j]=b[i];
b[i]=temp;
}
printf("\n enter the space for required process:");
scanf("%d",&s);
for(i=1;i<=a;i++)
`
{
if(s<=b[i])
{
printf("\n the best fit for the required space is :%d\n",b[i]);
break;
}
}
}
Output:
===================BEST FIT======================
ENTER THE NO OF UNALLOCATED SPACES: 3
ENTER THE UNALLOCATED SPACE IN KB:
10
15
20
ENTER THE SPACE FOR REQUIRED PROCESS: 8
THE BEST FIT FOR THE REQUIRED SPACE IS: 10
Result:
The program for best fit was implemented and hence verified
Aim:
To write a program to implement best fit algorithm for memory management.
Algorithm:
1. Start the process
2. Declare the size
3. Get the number of processes to be inserted
4. Allocate the first hole that is big enough searching
5. Start at the beginning of the set of holes
6. If not start at the hole that is sharing the pervious first fit search end
7. Compare the hole
8. if large enough then stop searching in the procedure
9. Display the values
10. Stop the process
Program:
#include<stdio.h>
main()
{
int i,j,n,ns,jb,c,ss[20];
printf("\n==========first fit==========");
printf("\nenter the number of slots:");
scanf("%d",&ns);
printf("\n enter %d slots:");
for(i=0;i<ns;i++)
scanf("%d",&jb);
do
{
printf("\n Enter the job size:");
scanf("%d",&jb);
for(i=0;i<ns;i++)
{
if(jb<=ss[i])
{
printf("\n %d is allocated to slot %d of size %d",jb,i+1,ss[i]);
ss[i]=ss[i]-jb;
printf("\n Remaining space of slot %d is= %d",i+1,ss[i]);
n=1;
break;
}
else
continue;
}
if(n!=1)
printf("\n %d is not allocated to any slot");
n=0;
printf("\n enter your choice:");
scanf("%d",&c);
}while(c==1);
}
Output:
==================FIRST FIT===================
ENTER THE NUMBER OF SLOTS: 4
ENTER 4 SLOTS: 12 23 34 45
ENTER THE JOB SIZE: 35
35 IS SLLOCATED TO SLOT 3 OF SIZE 34
REMAINING SPACE OF SLOT 3 IS=9
ENTER YOUR CHOICE: 1
ENTER JOB SIZE: 13
13 IS ALLOCATED TO SLOT 2 OF SIZE 23
REMAINING SPACE OF SLOT 2 IS =10
ENTER YOUR CHOICE: 2
Result:
The program for first fit was implemented and hence verified
Aim:
Algorithm:
1. Start the process
2. Declare the size
3. Get the number of processes to be inserted
4. Allocate the first hole that is big enough searching
5. Start at the beginning of the set of holes
6. If not start at the hole that is sharing the pervious first fit search end
7. Compare the hole
8. if large enough then stop searching in the procedure
9. Display the values
10. Stop the process
Program:
#include<stdio.h>
int main()
{
int a[50],n,i,j,p,t;
printf("\n=============WORST FIT============");
Output:
====================WORST FIT=====================
ENTER THE NUMBER OF UNALLOCATED MEMORIES: 4
ENTER THE MEMORY SPACE:
12
23
34
45
ENTER THE MEMORY REQUIRED FOR THE PROCESS: 25
THE WORST FIT OF THE PROCESS: 45
Result:
Thus the program is verified.
PROCESS
SYNCHRONIZATION
Semaphore sread=0,swrite=0;
Int ch,r=0;
Clrscr();
Printf(readers writers problem);
Do
{
Printf(\n MENU);
Printf(\n \t 1.read from the file);
Printf(\n\t 2.write to the file);
Printf(\n\t 3.exit a reader);
Printf(\n\t 4.exit a writer);
Printf(\n\t 5. status of the file);
Printf(\n\t 6.exit);
Printf(\n enter your choice);
Scanf(%d,&ch);
Switch(ch)
{
Case 1:
If(swrite==0)
{
Sread=1;
R=r+1;
Printf(\n reader %d reads the file\n,r);
}
Else
Printf(\n cannot read while writer writes to the file\n);
Break;
Case 2:
If(sread==0&&swrite==0)
{
Swrite=1;
Printf(\n writer %d writes the file\n);
}
Else
If(sread==1)
Printf(\n cannot write while readers read the file\n);
Else if(swrite==1)
Printf(\n already one writer is writing to the filw\n);
Break;
Case 3:
If(r!=0)
{
Printf(\n the reader %d closes the file\n);
R=r-1;
If(r==0)
{
Printf(\n currently no reader are using the file\n);
Sread=0;
}
Else if(r==1)
Printf(\n currently only one reader is reading the file\n);
Else
Printf(\n currently %d readers are reading the file\n);
}
Break;
Case 4:
If(swrite==1)
{
Printf(\n writer closes the file);
Swrite=0;
}
Else
Printe(\n there is no writer writing to the file);
Break;
Case 5:
If(sread==1)
{
If(r==1)
Printf(\n readers are reading the file,r);
}
Else if(swrite==1)
Printf(\n writer is writing the file);
Else
Printf(\n the file is not in use);
Break;
Case 6:
Break;
}
}
While(ch!=6);
Return 0;
}
Output:
==========READER WRITER PROBLEM===========
MAIN MENU
R--------------->READER
W--------------->WRITER
N--------------->NONE
ENTER THE CHOICE.....R
R--------->READ DATABASE
X--------->EXIT DATABASE
MAIN MENU
R--------------->READER
W--------------->WRITER
N--------------->NONE
ENTER THE CHOICE.....R
R--------->READ DATABASE
X--------->EXIT DATABASE
ENTER THE CODE......X
THERE IS NO READER
MAIN MENU
R--------------->READER
W--------------->WRITER
N--------------->NONE
ENTER THE CHOICE.....W
W------->WRITE INTO DATABASE
X------->EXIT DATABASE
ENTER THE CODE.....W
MAIN MENU
R--------------->READER
W--------------->WRITER
N--------------->NONE
ENTER THE CHOICE.....W
W------->WRITE INTO DATABASE
X------->EXIT DATABASE
ENTER THE CODE.....X
WRITER EXIT THE DATABASE
MAIN MENU
R--------------->READER
W--------------->WRITER
N--------------->NONE
ENTER THE CHOICE.....N
Algorithm:
Step 1: Start.
Program:
#include<stdio.h>
main()
{
int in=0,out=0,c,b[20],bs,i,count=0;
printf("\n enter buffer size");
scanf("%d",&bs);
for(i=1;i<bs;i++)
b[1]=0;
do
{
printf("\n 1. producer\n 2.consumer\n 3.buffer\n4.exit");
scanf("%d",&c);
switch(c)
{
case 1:
if(count==bs)
printf("\n buffer is full\n");
else
{
printf("\n enter the item produced\t");
scanf("%d",&i);
b[in]=i;
in=(in+1)%bs;
count++;
}
break;
case 2:
if(count==0)
printf("\n buffer is empty\n");
else
{
i=b[out];
b[out]=0;
out=(out+1)%bs;
count--;
printf("\n consumed item is%d\n",i);
}
break;
case 3:
for(i=0;i<bs;i++)
printf("%d",b[i]);
printf("\n");
break;
}
}
while(c<=4);
}
Output:
enter buffer size4
1. producer
2.consumer
3.buffer
4.exit1
enter the item produced
1. producer
2.consumer
3.buffer
4.exit1
enter the item produced
1. producer
2.consumer
3.buffer
4.exit1
enter the item produced
1. producer
2.consumer
3.buffer
4.exit1
enter the item produced
1. producer
2.consumer
3.buffer
4.exit2
consumed item is8
1. producer
2.consumer
3.buffer
4.exit2
consumed item is7
1. producer
2.consumer
3.buffer
4.exit2
consumed item is9
1. producer
2.consumer
3.buffer
4.exit2
consumed item is6
1. producer
2.consumer
3.buffer
4.exit3
0000
1. producer
2.consumer
3.buffer
4.exit
Result:
Thus the program is verified.
MEMORY MANAGEMENT
SCHEME-II
PAGING
Aim :
To implement the C program using Paging Technique.
Algorithm :
Step 1 : Start the program.
Step 2 : Declare the structure namely p stable and p count.
Step 3 : Intialise the required variable.
Step 4 : Get the memory information such as no of pages and page size.
Step 5 : Get the starting address for each page and the datas for each page.
Step 6 : Print the page datas and page tables details namely page no and starting
address that was ready .
Step 7 : Else print the data not found.
Step 8 : Stop the program.
Program :
#include<stdio.h>
#include<conio.h>
struct ptable
{
int pno,staddr;
}p[50];
struct pcount
{
int pno;
char data[50];
}pg[24][24];
void main()
{
int n,size,i,j,k,st,pagenum,disp,phyaddr,laddr,found=0;
clrscr();
printf("\n\t\tMemory information\n");
printf("\t*********************************\n");
printf("Enter the no pages:\n");
printf("Enter the page size:\n");
scanf("%d",&size);
for(i=1;i<=n;i++)
{
printf("Enter the starting address for the page:[%d]\n",i);
scanf("%d",&st);
for(j=1;j<=size;j++)
{
printf("Page[%d]\tdata:",st);
scanf("%s",pg[i][j].data);
pg[i][j].pno=st;
st=st+1;
}
}
printf("\n\t\tMemory\n");
printf("\t*********************\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=size;j++)
{
printf("\npage[%d]\tdata:%s\n",pg[i][j].pno,pg[i][j].data);
}
}
printf("\n\t Page details\n");
printf("\t***********************\n");
printf("\nEnter the starting address for the pages");
for(k=1;k<=n;k++)
{
printf("\npage[%d]\tstarting address:\n",k);
p[k].pno=k;
scanf("%d",&p[k].staddr);
}
printf("\npageno\tstarting address\n");
for(k=1;k<=n;k++)
{
printf("\n%d\t\t%d\n",p[k].pno,p[k].staddr);
}
for(j=1;j<=size;j++)
{
if(pg[pagenum][j].pno==phyaddr)
printf("\nData:%s\n",pg[pagenum][j].data);
}
}
else
printf("\nNot found\n");
}
Output:
MEMORY INFORMATION
*********************************
Enter the no pages:
2
Enter the page size:
2
Enter the starting address for the page:[1]
100
Page[100]
data: SENTHIL
Page[101]
data: SURIYA
Enter the starting address for the page:[2]
200
Page[200]
data: TAMIZH
Page[201]
data: VENU
Memory
****************************
page[100]
data: SENTHIL
page[101]
data: SURIYA
page[200]
data: TAMIZH
page[201]
data: VENU
Page details
********** **********************************
Enter the starting address for the pages
page[1] starting address:
100
page[2] starting address:
200
pageno starting address
1
100
200
SEGMENTATION
Aim :
To write a C program for explaining the concept of Segmentation.
Algorithm :
Step 1 : Start the program.
Step 2 : Declare the structure table and its variables.
Step 3 : Read the no of arguments.
Step 4 : Get the starting address and limit of the segment.
Step 5 : Read the data for the corresponding segments.
Step 6 : Display the segment table details.
Step 7 : Stop the program.
Program :
#include<stdio.h>
#include<conio.h>
struct stable
{
int sno;
int staddr;
int limit;
}
s[50];
struct segcount
{
int snum;
char data[25];
}
seg[25][25];
void main()
{
int n,m,i,j,k=1,st,end,laddr,segnum,disp,phyaddr,found=0,limit;
clrscr();
printf("\n\t\tMEMORY INFORMATION");
printf("\n\t************************");
printf("\nEnter the no of segment :");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\nEnter the starting address and the limit of the segment[%d]:\n",i);
scanf("%d%d",&st,&limit);
end=st+limit;
s[k].sno=i;
s[k].staddr=st;
s[k].limit=limit;
k++;
for(j=st;j<end;j++)
{
printf("\nSegment[%d]\tdata : ",st);
scanf("%s",seg[i][j].data);
seg[i][j].snum=st;
st=st+1;
}
}
printf("Memory address\tdata : \n");
for(i=1;i<=n;i++)
for(j=s[i].staddr;j<s[i].staddr+s[i].limit;j++)
printf("%d\t\t%s\n",seg[i][j].snum,seg[i][j].data);
printf("\n\t\tSegment table details \n");
printf("\n\t**************************");
printf("\nSegment\t\tstarting address\t\tlength\n");
for(m=1;m<=n;m++)
{
printf("%d\t\t%d\t\t%d\n",m,s[m].staddr,s[m].limit);
}
printf("\nEnter the logical address :");
scanf("%d",&laddr);
segnum=laddr/100;
disp=laddr%100;
printf("\nSegment no : %d\ndisp : %d\n",segnum,disp);
for(k=1;k<=n;k++)
{
if(s[k].sno==segnum)
{
phyaddr=s[k].staddr+disp;
found=1;
break;
}
if(found==1)
{
printf("\nPhysical address : %d\n",phyaddr);
for(j=1;j<=n;j++)
{
if(seg[segnum][j].snum==phyaddr)
printf("\nData : %s\n",seg[segnum][j].data);
}
}
else
{
printf("\nNot Found");
}
}
}
Output:
MEMORY INFORMATION
********************* ************************
Enter the no of segment :
2
Enter the starting address and the limit of the segment[1]:
300
3
Segment[300]
data : WIND
Segment[301]
data : AIR
Segment[302]
data : WATER
data : ICE
Segment[21]
data : FIRE
starting address
300
20
length
SYSTEM CALL
PROCESS CREATION
Aim:
To write a c program for implementing the process creation
Algorithm:
Step1:Start the program
Step2:Include the header files
Step3:Call the fork function and equate this value of pid
Step4:Check whether the value of pid is 0
Step5:If the value is 0 means open the files and type message
Step6:Other wise read the file and print the message
Step7: Stop the program
Program:
#include<stdio.h>
void par_proc();
void chi_proc();
void slee_proc();
int main();
{
int n;
char c;
loop:
printf("=========CREATION OF PROCESS===========");
printf("\n1.parent process\n2. child process\n3.sleep process\n);
printf("ENTER YOUR CHOICE FROM 1 TO 3\n");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\n Parent process");
par_proc();
break;
case 2:
printf("\n Child Process");
chi_proc();
break;
case 3:
printf("\n Sleep process");
slee_proc();
break;
default:
printf("\n Try Again ENter correct choice");
}
printf("\n If U Want to continue(Y/N)...\n");
scanf(""%s",&c);
if(c==||'y'||c=='Y')
goto loop;
else
exit(1);
}
void par_proc()
{
int pid;
pid=getpid();
fflush(stdin);
printf("\n Process ID=%d\n",pid);
printf("\n");
}
void chi_proc()
{
int pid;
pid=fork();
if(pid==0)
{
fflush(stdin);
printf("\n Child ID=%d\n",getpid());
printf("\n Child's Parent ID=%d\n",getpid()); }
else
{
printf("\n Parent ID=%d\n",getpid());
printf("\n Parent's parent if=%d\n",getpid());
}}
void slee_proc()
{
int pid;
pid=getpid();
sleep(5);
printf("\n Process ID=%d\n",getpid());
printf("\n");
}
Output:
===============CREATION OF PROCESS================
1. PARENT PROCESS
2. CHILD PROCESS
3. SLEEP PROCESS
ENTER YOUR CHOICE FROM 1 TO 3
1
PARENT PROCESS
PROCESS ID=15918
IF YOU WANT TO CONTINUE(Y/N)........Y
===============CREATION OF PROCESS================
1. PARENT PROCESS
2. CHILD PROCESS
3. SLEEP PROCESS
ENTER YOUR CHOICE FROM 1 TO 3
2
CHILD PROCESS
CHILD ID=15919
CHILD'S PARENT ID=15919
IF YOU WANT TO CONTINUE(Y/N)....Y
===============CREATION OF PROCESS================
1. PARENT PROCESS
2. CHILD PROCESS
3. SLEEP PROCESS
ENTER YOUR CHOICE FROM 1 TO 3
3
SLEEP PROCESS
PROCESS ID=15919
IF YOU WANT TO CONTINUE(Y/N)....N
Result:
Thus the program is verified.
Algorithm:
1. Start the process
2. Declare the size and data variables
3. Get the number of processes to be inserted
4. Get the value
5. Start and identify the process with process id
6. Make a common function to communicate with each process running in
shared memory
7. Make the variables and arguments to be a global while in communication
8. Write a separate routine for creating memory delete memory in separate region
9. Give permission that a process can kill shared memory
10. Display the values
11. Stop the process
Program:
#include<sys/types.h>
#include<sys/shm.h>
#include<sys/ipc.h>
main()
{
int shmid;
key_t key=0x10;
shmid=shmget(key,100,IPC_CREAT|0666);
if( shmid < 0 )
printf("\nFirst SHMID failed\n");
else
printf("\nFirst SHMID Succeded id=%d \n",shmid);
shmid=shmget(key,101,IPC_CREAT|0666);
if(shmid<0)
printf("\nSecond SHMID failed\n");
else
printf("\nSecond SHMID Succeded id=%d \n",shmid);
shmid=shmget(key,90,IPC_CREAT|0666);
if(shmid<0)
printf("\nThird SHMID failed\n");
else
printf("\n Third SHMID Succeded id=%d \n",shmid);
}
Output:
First SHMID Succeded id=589836
Second SHMID failed
Third SHMID Succeded id=589836
Result:
The program for creation of shared memory was implemented and hence verified.
Algorithm:
1. Start
2. Read the input as one of its filename
3. Check the permission
4. Using change mode command we can change the permission of file
5. Display the changes and verify it by opeing the file and modify the contents
6. Repeat the process changing the permission
7. Stop the process
Program:
ls -l
echo "enter the file name to be locked";
read f;
echo $f;
ls -l $f
echo "1.read only \n";
echo "2.read write \n";
read c;
if [ $c == 1 ]
then
chmod 444 $f
ls -l $f
elif [ $c == 2 ]
then
chmod 666 $f
ls -l $f
else
echo "wrong choice";
fi
Output:
$ sh lock.sh
-rw-rw-rw-
-rw-rw-r--
-rw-rw-r--
1.read only \n
2.read write \n
1
-r--r--r-$
Result:
The program for the file locking was implemented and hence verified