0% found this document useful (0 votes)
29 views

OS-SET 1 - Answers

The document discusses C programs for implementing different memory allocation strategies and scheduling algorithms. It includes programs for first fit memory allocation, indexed file allocation, implementing threading using mutex, priority scheduling and round robin scheduling. For each concept, it provides the algorithm, sample code and sample output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

OS-SET 1 - Answers

The document discusses C programs for implementing different memory allocation strategies and scheduling algorithms. It includes programs for first fit memory allocation, indexed file allocation, implementing threading using mutex, priority scheduling and round robin scheduling. For each concept, it provides the algorithm, sample code and sample output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 57

SET – 1

OPERATING SYSTEM LAB ANSWERS

1. a. Write a C program to implement First Fit Memory Allocation Method


AIM:
To allocate memory requirements for processes using first fit allocation

ALGORITHM:
Step 1: Declare structures hole and process to hold information about set of holes and processes
respectively.
Step 2: Get number of holes, say nh. Get the size of each hole.
Step 3: Get number of processes, say np. Get the memory requirements for each process.
Step 4: Allocate processes to holes, by examining each hole as follows:
a.If hole size > process size then
i.Mark process as allocated to that hole.
ii.Decrement hole size by process size.
b.Otherwise check the next from the set of hole
Step 5: Print the list of process and their allocated holes or unallocated status.
Step 6: Print the list of holes, their actual and current availability.
Step 7: Stop the program.
PROGRAM:
#include <stdio.h>
struct process
{
int size; int flag;
int holeid;
} p[10];
struct hole
{
int size;
int actual;
} h[10];
main()
{
int i, np, nh, j;
printf("Enter the number of Holes : ");
scanf("%d", &nh);
for(i=0; i<nh; i++)
{
printf("Enter size for hole H%d : ",i);
scanf("%d", &h[i].size);
h[i].actual = h[i].size;
}
printf("\nEnter number of process : " );
scanf("%d",&np);
for(i=0;i<np;i++)
{
printf("enter the size of process P%d : ",i);
scanf("%d", &p[i].size);
p[i].flag = 0;
}

for(i=0; i<np; i++)


{
for(j=0; j<nh; j++)
{
if(p[i].flag != 1)
{
if(p[i].size <= h[j].size)
{
p[i].flag = 1; p[i].holeid = j;
h[j].size-= p[i].size;
}
}
}
}
printf("\n\tFirst fit\n"); printf("\nProcess\tPSize\tHole"); for(i=0; i<np; i++)
{
if(p[i].flag != 1)
printf("\nP%d\t%d\tNot allocated", i, p[i].size);
else
}
printf("\nP%d\t%d\tH%d", i, p[i].size, p[i].holeid);
printf("\n\nHole\tActual\tAvailable");
for(i=0; i<nh ;i++)
printf("\nH%d\t%d\t%d", i, h[i].actual, h[i].size);
printf("\n");
}

OUTPUT:
Enter the number of Holes: 5
Enter size of hole H0 : 100
Enter size of hole H1 : 500
Enter size of hole H2 : 200
Enter size of hole H3 : 300
Enter size of hole H4 : 600
Enter number of process : 4
Enter the size of process P0 :
212
Enter the size of process P1 : 417
Enter the size of process P2 : 112
Enter the size of process P3 : 426

First fit
Hole
Process PSize
P0 212 H1
P1 417 H4
P2 112 H1
P3 426 Not allocated

Hole Actual Available


H0 100 100
H1 500 176
H2 200 200
H3 300 300
H4 600 183

2. a. Write a C program to implement Indexed file allocation Strategy

AIM:
To write a C program to implement the indexed file allocation technique.

ALGORITHM:
Step 1: Initialize all the required variables.
Step 2: Receive inputs for number of files and file names.
Step 3: For each file, input the number of blocks occupied by the file and the size of each block in kb.
Step 4: After receiving these inputs, allocate each file in the consecutive blocks that are free.
Step 5: The file is allocated to the given blocks.
Step 6: Display the file name that is asked by the user along with its starting address, number of blocks and
actual file allocation.

CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
int n;
void main()
{
int b[20],b1[20],i,j,blocks[20][20],sz[20];
char F[20][20],S[20],ch;
clrscr();
printf("\n Enter the number of Files: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter the file %d name: ",i+1);
scanf("%s",&F[i]);
printf("\n Enter the file %d size(in kb): ",i+1);
scanf("%d",&sz[i]);
printf("\n Enter block size of File %d(in bytes): ",i+1);
scanf("%d",&b[i]);
}
for(i=0;i<n;i++)
{
b1[i]=(sz[i]*1024)/b[i];
printf("\n\n Enter blocks for file %d",i+1);
for(j=0;j<b1[i];j++)
{
printf("\n Enter the %d block ::",j+1);
scanf("%d",&blocks[i][j]);
}
}
do
{
printf("\n Enter the Filename: ");
scanf("%s",&S);
for(i=0;i<n;i++)
{
if(strcmp(F[i],S)==0)
{
printf("\nFname\tFsize\tBsize\tNblocks\tBlocks\n");
printf("\n \n");
printf("\n%s\t%d\t%d\t%d\t",F[i],sz[i],b[i],b1[i]);
for(j=0;j<b1[i];j++)
printf("%d->",blocks[i][j]);
}
}
printf("\n \n");
printf("\nDo U want to continue ::(y:n)");
scanf("%d",&ch);
}
while(ch!=0);
}

OUTPUT:
3. a. Implement the concept of Threading using C Program

AIM:
To write a C program to implement threading and synchronization application.

ALGORITHM:
Step 1: Start the process..
Step 2: A mutex is initialized in the beginning of the main function.
Step 3: The same mutex is locked in the ‘doSomeThing()’ function while using the shared resource
‘counter’
Step 4: At the end of the function ‘doSomeThing()’ the same mutex is unlocked.
Step 5: At the end of the main function when both the threads are done, the mutex is destroyed.
Step 6: Stop the process.

CODE:
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
pthread_t tid[2];
int counter;
pthread_mutex_t lock;

void* doSomeThing(void *arg)


{
pthread_mutex_lock(&lock);
unsigned long i = 0;
counter += 1;
printf("\n Job %d started\n", counter);
for(i=0; i<(0xFFFFFFFF);i++);
printf("\n Job %d finished\n", counter);
pthread_mutex_unlock(&lock);
return NULL;
}
int main(void)
{
int i = 0; int err;
if (pthread_mutex_init(&lock, NULL) != 0)
{
printf("\n mutex init failed\n");
return 1;
}
while(i < 2)
{
err = pthread_create(&(tid[i]), NULL, &doSomeThing, NULL);
if (err != 0)
printf("\ncan't create thread :[%s]", strerror(err));
i++;
}
pthread_join(tid[0], NULL);
pthread_join(tid[1], NULL);
pthread_mutex_destroy(&lock);
return 0;
}

OUTPUT:
4. a. Write a C program to implement Priority Scheduling algorithm

AIM:
To write a C program to execute the Priority scheduling algorithm.

ALGORITHM:
Step 1: Get the number of process
Step 2: Get the id and service time for each process.
Step 3: Initially the waiting time of first short process as 0 and total time of first short is process the
service time of that process.
Step 4: Calculate the total time and waiting time of remaining process.
Step 5: Waiting time of one process is the total time of the previous process.
Step 6: Total time of process is calculated by adding the waiting time and service time of each
process.
Step 7: Total waiting time calculated by adding the waiting time of each process.
Step 8: Total turn around time calculated by adding all total time of each process.
Step 9: Calculate average waiting time by dividing the total waiting time by total number of process.
Step 10: Calculate average turn around time by dividing the total waiting time by total number of
process.
Step 11: Display the result.

CODE:
#include<stdio.h>
int enqueue(int num, int y, int q[]);
int main()
{
int p[5],b[5],w[5],f[5], n, tb, t[5], i, j, tw, tt, temp, wt, pr[10], c[10];
float aw, at;
printf("\n Enter the no. of process:");
scanf("%d", &n);
for(i=0;i<n; i++)
{
printf("Enter the burst time & priority:");
scanf("%d", &b[i]);
scanf("%d", &pr[i]); p[i]=i+1;
}
for(i=0;i<n; i++)
for(j=i+1;j<n; j++)
if(pr[i]>pr[j])
{
temp=pr[i]; pr[i]=pr[j]; pr[j]=temp; temp=b[i]; b[i]=b[j]; b[j]=temp; temp=p[i]; p[i]=p[j]; p[j]=temp;
}
tw=w[0]=tt=t[0]=tb=0;
for(i=0; i<n; i++)
{

w[i]=tb;
tb=tb+b[i];
t[i]=b[i]+w[i];
tw=tw+w[i];
tt=tt+t[i];
}
aw=(float)tw/n;
at=(float)tt/n;
for(i=0;i<n;i++)
c[i]=w[i];
c[n]=t[n-1];
printf("\n Process time Burst time Waiting time Turnaround time\n"); for(i=0;i<n;i++)
printf("\n\t%d\t\t%d\t\t%d\t\t%d\n",p[i],b[i],w[i],t[i]); printf("\nGantt chart\n");
for(i=0;i<=n;i++)
for(j=i+1;j<=n;j++)
if(c[i]>c[j])
{
temp=c[i]; c[i]=c[j]; c[j]=temp;
}
for(i=0;i<n;i++)
printf("\t p%d",p[i]);
printf("\n");
for(i=0;i<=n;i++)
printf("\t%d",c[i]);
printf("\n The total waiting time=%d",tw);
printf("\n Total turnaround time is=%d",tt);
printf("\n Average waiting time=%f",aw);
printf("\n Average turnaround time=%f",at);
printf("\n");
}

OUTPUT:
5. a. Write a C program to implement Round Robin Scheduling algorithm
AIM:
To write a C program to execute the Round Robin scheduling algorithm.

ALGORITHM:
Step 1: Initialize all the structure elements.
Step 2: Receive inputs from the user to fill process id, burst time and arrival
time.
Step 3: Calculate the waiting time for all the process id.
i) The waiting time for first instance of a process is calculated as: a[i].waittime=count +
a[i].arrivt
ii) The waiting time for the rest of the instances of the process is calculated as:
a) If the time quantum is greater than the remaining burst time then waiting time is
calculated as: a[i].waittime=count + tq
b) Else if the time quantum is greater than the remaining burst time then waiting time
is calculated as: a[i].waittime=count - remaining burst time
Step 4: Calculate the average waiting time and average turnaround time.
Step 5: Print the results of the step 4.
CODE:
#include<stdio.h>
#include<conio.h>
int enqueue(int num, int y, int q[]);
void main()
{
int queue[20],i,pro[20];
int rear=0,num,tq,bur[20],wt[20],turn[20];
int flag,j=1,temp,burst[20],wait[20];
float avgwt=0,avgturn=0;
wt[0]=0;
clrscr();
printf("\n ROUND ROBIN SCHEDULING\n");
printf("\n\nEnter the number of process:");
scanf("%d",&num); printf("\nProcess\
tBurst time\n"); for(i=0;i<num;i++)
{
printf("\n p%d\t\t",i+1);
scanf("%d",&bur[i]);
burst[i]=bur[i];
}
printf("\n\nEnter the time quantum:");
scanf("%d",&tq);
do
{
flag=0;
for(i=0;i<num;i++)
{
if(bur[i]>=tq)
{
rear=enqueue(i+1,rear,queue);
bur[i]-=tq;
wt[j]=tq+wt[j-1];
j++;
}
else if((bur[i]>0)&&(bur[i]<tq))
{
rear=enqueue(i+1,rear,queue);
wt[j]=bur[i]+wt[j-1];
bur[i]=0;
j++;
}
}
for(i=0;i<num;i++)
if(bur[i]==0)
flag++;
}while(flag!=num);
for(i=1;i<=rear;i++)
queue[i-1]=queue[i];
printf("\n\nGANTT CHART\n");
for(i=0;i<rear;i++)
printf("p%d\t",queue[i]); printf("\n");
for(i=0;i<=rear;i++)
printf("%d\t",wt[i]);
for(i=0;i<num;i++)
{
wait[i]=0;
temp=0;
for(j=0;j<rear;j++)
{
if(queue[j]==i+1)
{
wait[i]+=(wt[j]-temp);
temp=wt[j+1];
}
}
}
printf("\n\n**********************************************************"); printf("\
nProcess\tBurst time \tWait time \tTurnaround time\n");
printf("**********************************************************\n");
for(i=0;i<num;i++)
turn[i]=wait[i]+burst[i]; printf("\np%d\t\t%d\t\t%d\t\t
%d",i+1,burst[i],wait[i],turn[i]); avgwt+=wait[i];
avgturn+=turn[i];
printf("\n\nAverage Waiting time is %f",avgwt/num);
printf("\n\nAverage Turnaround time is %f",avgturn/num);
getch();
}
int enqueue(int n,int rear,int queue[])
{
rear++;
queue[rear]=n;
return rear;
}
OUTPUT:
6. a. Write a C program to implement Worst Fit Memory Allocation Method

AIM:
To allocate memory requirements for processes using worst fit allocation.

ALGORITHM:
Step 1: Get the number of blocks and size of the blocks.
Step 2: Get number of holes and the size of each hole.
Step 3: Get number of processes and the memory requirements for each process.
Step 4: Allocate processes to holes, by examining each hole as follows:
a. Sort according to their sizes in descending order
b. If block size > file size then
i. Mark file as allocated to that block.
ii. Decrement block size by file size.
c. Otherwise check the next from the set of sorted block
Step 5: Print the list of process and their allocated holes or unallocated status.
Step 6: Stop the program.

PROGRAM:
#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;
static int bf[max],ff[max];
clrscr();
printf("\n\tMemory Management Scheme - Worst Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block %d:",i);
scanf("%d",&b[i]);}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1) //if bf[j] is not allocated
{
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();
}
OUTPUT:
7. a. Write a C program to implement Best Fit Memory Allocation Method
AIM:
To allocate memory requirements for processes using best fit allocation

ALGORITHM:
Step 1: Declare structures hole and process to hold information about set of holes and processes
respectively.
Step 2: Get number of holes, say nh. Get the size of each hole.
Step 3: Get number of processes, say np. Get the memory requirements for each process.
Step 4: Allocate processes to holes, by examining each hole as follows:
a. Sort the holes according to their sizes in ascending order
b. If hole size > process size then
i. Mark process as allocated to that hole.
ii. Decrement hole size by process size.
c. Otherwise check the next from the set of sorted hole
Step 5: Print the list of process and their allocated holes or unallocated status.
Step 6: Print the list of holes, their actual and current availability.
Step 7: Stop the program.
PROGRAM:
#include <stdio.h>
struct process
{
int size;
int flag;
int holeid;
} p[10];
struct hole
{
int hid;
int size;
int actual;
} h[10];
main()
{
int i, np, nh, j;
void bsort(struct hole[], int);
printf("Enter the number of Holes : ");
scanf("%d", &nh);
for(i=0; i<nh; i++)
{
printf("Enter size for hole H%d : ",i);
scanf("%d", &h[i].size);
h[i].actual = h[i].size; h[i].hid = i;
}
printf("\nEnter number of process : " );
scanf("%d",&np);
for(i=0;i<np;i++)
{
printf("enter the size of process P%d : ",i);
scanf("%d", &p[i].size);
p[i].flag = 0;
}
for(i=0; i<np; i++)
{
bsort(h, nh); for(j=0; j<nh; j++)
{
if(p[i].flag != 1)
{
if(p[i].size <= h[j].size)
{
p[i].flag = 1; p[i].holeid = h[j].hid;
h[j].size -= p[i].size;
}
}
}
}
printf("\n\tBest fit\n");
printf("\nProcess\tPSize\tHole");
for(i=0; i<np; i++)
{
if(p[i].flag != 1)
printf("\nP%d\t%d\tNot allocated", i, p[i].size);
else
}
printf("\nP%d\t%d\tH%d", i, p[i].size, p[i].holeid);
printf("\n\nHole\tActual\tAvailable");
for(i=0; i<nh ;i++)
printf("\nH%d\t%d\t%d", h[i].hid, h[i].actual, h[i].size);
printf("\n");
}
void bsort(struct hole bh[], int n)
{
struct hole temp;
int i,j;
for(i=0; i<n-1; i++)
{
for(j=i+1; j<n; j++)
{
if(bh[i].size > bh[j].size)
{
temp = bh[i];
bh[i] = bh[j];
bh[j] = temp;
}}
}}

OUTPUT:
Enter the number of Holes: 5
Enter size of hole H0 : 100 Enter
size of hole H1 : 500 Enter size
of hole H2 : 200 Enter size of
hole H3 : 300 Enter size of hole
H4 : 600 Enter number of
process : 4
Enter the size of process P0 :

212
Enter the size of process P1 : 417
Enter the size of process P2 : 112
Enter the size of process P3 : 426
Best fit
Hole
Process PSize
P0 212 H3
P1 417 H1
P2 112 H2
P3 426 H4

Hole Actual Available


H0 500 83
H1 300 88
H2 200 88
H3 100 100
H4 600 174

8. a. How the data is allocated sequentially, write a C program to implement


AIM:
To write a C program to implement the sequential file allocation technique.

ALGORITHM:
Step 1: Initialize all the required variables.
Step 2: Receive inputs for number of files and file names.
Step 3: For each file, input the number of blocks occupied by the file and the starting block.
Step 4: After receiving these inputs, allocate each file one after another in a sequential manner.
Step 5: The file length is added and it serves as the starting block for the next file.
Step 6: Display the file name that is asked by the user along with its starting address, number of blocks and
actual file allocation.

CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int st[20],b[20],b1[20],ch,i,j,n,blocks[20][20],sz[20];
char F[20][20],S[20];
clrscr();
printf("\n Enter no. of Files ::");
scanf("%d",&n); for(i=0;i<n;i++)
{
printf("\n Enter file %d name ::",i+1);
scanf("%s",&F[i]);
printf("\n Enter file%d size(in kb)::",i+1);
scanf("%d",&sz[i]);
printf("\n Enter Starting block of %d::",i+1);
scanf("%d",&st[i]);
printf("\n Enter blocksize of File%d(in bytes)::",i+1);
scanf("%d",&b[i]);
}
for(i=0;i<n;i++)
b1[i]=(sz[i]*1024)/b[i];
for(i=0;i<n;i++)
{
for(j=0;j<b1[i];j++)
blocks[i][j]=st[i]+j;
}
do
{
printf("\nEnter the Filename ::");
scanf("%s",S);
for(i=0;i<n;i++)
{
if(strcmp(S,F[i])==0)
{
printf("\nFname\tStart\tNblocks\tBlocks\n");
printf("\n \n");
printf("\n%s\t%d\t%d\t",F[i],st[i],b1[i]);
for(j=0;j<b1[i];j++)
printf("%d->",blocks[i][j]);
}
}
printf("\n \n");
printf("\nDo U want to continue ::(Y:n)");
scanf("%d",&ch);
if(ch!=1)
break;
}while(1);
}

OUTPUT:
9. a. Write a C program to implement SJF Scheduling algorithm
AIM:
To write a C program to execute the Shortest Job First scheduling algorithm.

ALGORITHM:
Step 1: Get the number of process.
Step 2: Get the id and service time for each process.
Step 3: Initially the waiting time of first short process as 0 and total time of first short is
process the service time of that process.
Step 4: Calculate the total time and waiting time of remaining process.
Step 5: Waiting time of one process is the total time of the previous process.
Step 6: Total time of process is calculated by adding the waiting time and service time of each
process.
Step 7: Total waiting time calculated by adding the waiting time of each process.
Step 8: Total turnaround time calculated by adding all total time of each process.
Step 9: Calculate average waiting time by dividing the total waiting time by total number of
process.
Step 10: Calculate average turnaround time by dividing the total waiting time by total number
of process.
Step 11: Display the result.
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int p[5],b[5],w[5],f[5],n,tb,t[5],i,j,tw,tt,temp,wt,c[10];
float aw,at;
clrscr();
printf("\n Enter the no. of process:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the burst time:");
scanf("%d",&b[i]);
p[i]=i+1;
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(b[i]>b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
tw=w[0]=tt=t[0]=tb=0;
for(i=0;i<n;i++)
{
w[i]=tb;
tb=tb+b[i];
t[i]=b[i]+w[i];

tw=tw+w[i];
tt=tt+t[i];
}
aw=(float)tw/n;
at=(float)tt/n;
for(i=0;i<n;i++)
c[i]=w[i];
c[n]=t[n-1];
printf("\n Process Burst time Waiting time Turnaround time\n");
for(i=0;i<n;i++)
printf("\np%d\t\t%d\t\t%d\t\t%d\n",p[i],b[i],w[i],t[i]); printf("\
nGantt chart\n");
for(i=0;i<=n;i++)
for(j=i+1;j<=n;j++)
if(c[i]>c[j])
{
temp=c[i];
c[i]=c[j];
c[j]=temp;
}
for(i=0;i<n;i++)
printf("\t p%d",p[i]);
printf("\n"); for(i=0;i<=n;i+
+)
printf("\t%d",c[i]);
printf("\n The total waiting time=%d",tw);
printf("\n Total turnaround time is=%d",tt);
printf("\n Average waiting time=%f",aw);
printf("\n Average turnaround time=%f",at);
printf("\n");
getch();
}
OUTPUT:
RESULT:
Thus the Shortest Job First scheduling algorithm is implemented.

10. a. Write a C program to implement FCFS Scheduling algorithm


AIM:
To write a C program to execute the First Come First Serve scheduling algorithm.

ALGORITHM:
Step 1: Create the number of process.
Step 2: Get the Burst time for each process.
Step 3: Initially, Waiting time of first process is zero and Total turn around time for the first
process is the starting time of that process.
Step 4: Calculate the Total time and Processing time for the remaining processes.
Step 5: Waiting time of one process is the Total time of the previous process.
Step 6: Total time of process is calculated by adding Waiting time and Burst time.
Step 7: Total waiting time is calculated by adding the waiting time for lack process.
Step 8: Total turnaround time is calculated by adding all total time of each process.
Step 9: Calculate Average waiting time by dividing the total waiting time by total number of
process.
Step 10: Calculate Average turnaround time by dividing the total time by the number of
process.
Step 11: Display the result.

CODE:
#include<stdio.h>
void main()
{
int a[10],b[10],c[10],n,i,wt=0;
float avgwt;
a[0]=b[0]=0;
clrscr();
printf("\nEnter the no. of processes\t");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the burst time:");
scanf("%d",&a[i]);
}
printf("\n The entered process are");
for(i=1;i<=n;i++)
printf("\np%d %d",i, a[i]);
printf("\n The gantt chart is:\n");
for(i=1;i<=n;i++)
{
printf("\t p%d",i);
}
printf("\n");
printf("\t%d",b[0]);
for(i=1;i<=n;i++)
{
b[i]=a[i]+b[i-1];
printf("\t%d",b[i]);
}
printf("\n The waiting time is");
for(i=0;i<n;i++)
{
printf("\np%d\t%d",i+1,b[i]);
wt=b[i]+wt;
}
avgwt=wt/i;
printf("\nThe average waiting time is %f",avgwt);
printf("\nThe turnaround time is");
wt=0;
for(i=1;i<=n;i++)
{
printf("\np%d\t%d",i,b[i]);
wt=b[i]+wt;
}
avgwt=wt/i;
printf("\nThe average turnaround time is %f",avgwt);
printf("\n");
getch();
}
OUTPUT:
RESULT:
Thus the First Come First Serve scheduling algorithm is implemented.
11. a. Write a C-program to implement the producer - consumer problem using semaphores.
AIM:
To write a C-program to implement the producer – consumer problem using
semaphores.

ALGORITHM:

Step 1: Start the program.


Step 2: Declare the required variables.
Step 3: Initialize the buffer size and get maximum item you want to produce.
Step 4: Get the option, which you want to do either producer, consumer or exit
from the operation.
Step 5: If you select the producer, check the buffer size if it is full the producer
should not produce the item or otherwise produce the item and increase the
value buffer size.
Step 6: If you select the consumer, check the buffer size if it is empty the consumer
should not consume the item or otherwise consume the item and decrease the
value of buffer size.
Step 7: If you select exit come out of the
program. Step 8: Stop the program.

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("\n1.PRODUCER\n2.CONSUMER\n3.EXIT\n");
while(1)
{
printf("\nENTER YOUR CHOICE\n");
scanf("%d",&n);
switch(n)
{
case 1:
if((mutex==1)&&(empty!=0))
producer();
else
printf("BUFFER IS FULL");
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);
x++;
printf("\nproducer produces the item%d",x);
mutex=signal(mutex);
}
void consumer()
{
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
printf("\n consumer consumes item%d",x);
x--;
mutex=signal(mutex);
}
12. a. Write a C program to implement banker’s algorithm for deadlock avoidance.
AIM:
To write a C program to implement Banker’s algorithm for Deadlock Avoidance.

ALGORITHM:
Step 1: Start the process.
Step 2: Read the number of processors and resources.
Step 3: Read the allocation matrix, alloc[ ][ ].
Step 4: Read the number of each resource type.
Step 5: Read the maximum claim table.
Step 6: For each resource j, calculate avail[j] by the following steps:
a.Set s=0;
b.For each process i, s+= a[i][j]. avail[j] =c[i]-s
Step 7: For each process i do the following
a.For each process j, do the following
i.x = max[i][j]-a[i][j]
b.If x<max[j]
i.If j = NR-1 and ith process is not already allocated
1.pr=1
2.Goto step 8
ii.Else, get out of internal loops
Step 8: If no process has been allocated so far, print ‘unsafe’ and exit.
Step 9: Else, calculate new available matrix by following steps:
a. For each resource j, do the following
i. avail[j]+ = a[pr][j]
ii. a[pr][j]=0
b. For each process i, do the following
i. For each resource j, do the following 1. If a[i][j]=0
a. If i = NP-1 and j = NR-1, print ‘Safe’
b. Else, goto step 6
Step 10: Stop the process.

CODE:
#include <stdio.h>
int curr[5][5], maxclaim[5][5], avl[5];
int alloc[5] = {0, 0, 0, 0, 0};
int maxres[5], running[5], safe=0;
int count = 0, i, j, exec, r, p, k = 1;
int main()
{
printf("\nEnter the number of processes: ");
scanf("%d", &p);
for (i = 0; i < p; i++)
{
running[i] = 1; count++;
}
printf("\nEnter the number of resources: ");
scanf("%d", &r);
for (i = 0; i < r; i++)
{
printf("\nEnter the resource for instance %d: ", k++);
scanf("%d", &maxres[i]);
}
printf("\nEnter maximum resource table:\n");
for (i = 0; i < p; i++)
{
for(j = 0; j < r; j++)
{
scanf("%d", &maxclaim[i][j]);
}
}
printf("\nEnter allocated resource table:\n");
for (i = 0; i < p; i++)
{
for(j = 0; j < r; j++)
{
scanf("%d", &curr[i][j]);
}
}
printf("\nThe resource of instances: ");
for (i = 0; i < r; i++)
{
printf("\t%d", maxres[i]);
}
printf("\nThe allocated resource table:\n");
for (i = 0; i < p; i++)
{
for (j = 0; j < r; j++)
{
printf("\t%d", curr[i][j]);
}
printf("\n");
}
printf("\nThe maximum resource table:\n");
for (i = 0; i < p; i++)
{
for (j = 0; j < r; j++)
{
printf("\t%d", maxclaim[i][j]);
}
printf("\n");
}
for (i = 0; i < p; i++)
{
for (j = 0; j < r; j++)
{
alloc[j] += curr[i][j];
}
}
printf("\nAllocated resources:");
for (i = 0; i < r; i++)
{
printf("\t%d", alloc[i]);
}
for (i = 0; i < r; i++)
{
avl[i] = maxres[i] - alloc[i];
}
printf("\nAvailable resources:");
for (i = 0; i < r; i++)
{
printf("\t%d", avl[i]);
}
printf("\n");
while (count != 0)
{
safe = 0;
for (i = 0; i < p; i++)
{
if (running[i])
{
exec = 1;
for (j = 0; j < r; j++)
{
if (maxclaim[i][j] - curr[i][j] > avl[j])
{
exec = 0; break;
}
}
if (exec)
{
printf("\nProcess%d is executing\n", i + 1);
running[i] = 0;
count--; safe = 1;
for (j = 0; j < r; j++)
{
avl[j] += curr[i][j];
}
break;
}
}
}
if (!safe)
{
}
else
{
printf("\nThe processes are in unsafe state.\n");
break;
printf("\nThe process is in safe state");
printf("\nSafe sequence is:");
for (i = 0; i < r; i++)
{
printf("\t%d", avl[i]);
}
printf("\n");
}
}
}

OUTPUT:
RESULT:
Thus the Banker’s algorithm for Deadlock avoidance is implemented.

13. a. Write a C program to implement algorithm for deadlock detection.


AIM:
To write a C program to implement an algorithm for deadlock detection.
ALGORITHM:
Step 1: Start the process.
Step 2: Read the number of processors and resources.
Step 3: Read the allocation matrix, alloc[ ][ ].
Step 4: Read the number of each resource type.
Step 5: Read the maximum claim table.
Step 6: Let Work and Finish be vectors of length m and n, respectively. Initialize:
(a) Work = Available
(b) For i = 1 to n, if Allocationi 0, then Finish[i] = false; else Finish[i] = true
Step 7: Find an index i such that both:
(a) Finish[i] == false
(b) Requesti == Work
If no such i exists, go to step 9
Step 8: Work = Work + Allocationi
Finish[i] = true go to step 7
Step 9: If Finish[i] == false, for some i, 0  i  n, then the system is in deadlock state.
CODE:
#include<stdio.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;
clrscr();
printf("********** Deadlock Detection Algo ************\n");
input();
show();
cal(); return 0;
}
void input()
{
int i,j;
printf("Enter the no of Processes\t");
scanf("%d",&n);
printf("Enter the no of resource instances\t");
scanf("%d",&r);
printf("Enter the Max Matrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
scanf("%d",&max[i][j]);
}
}
printf("Enter the Allocation Matrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
scanf("%d",&alloc[i][j]);
}
}
printf("Enter the available Resources\n");
for(j=0;j<r;j++)
{
scanf("%d",&avail[j]);
}
}
void show()
{
int i,j;
printf("Process\t Allocation\t Max\t Available\t");
for(i=0;i<n;i++)
{
printf("\nP%d\t ",i+1);
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;
int dead[100];
int safe[100]; int i,j;
for(i=0;i<n;i++)
{
finish[i]=0;
}
//find need matrix for(i=0;i<n;i++)
{
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++;
if(c==r)
{
for(k=0;k<r;k++)
{
avail[k]+=alloc[i][j]; finish[i]=1;
flag=1;
}
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;
}
}
if(flag==1)
{
printf("\n\nSystem is in Deadlock and the Deadlock process are\n");
for(i=0;i<n;i++)
{
printf("P%d\t",dead[i]);
}
}
else
{
printf("\nNo Deadlock Occur");
}
}OUTPU

14. a Write a C program for implementation of FIFO page replacement algorithm.

AIM:
To write a C program to execute the First In First Out (FIFO) page replacement algorithm.
ALGORITHM:
Step 1: Start the process.
Step 2: Read number of pages n.
Step 3: Read number of pages number.
Step 4: Read page numbers into an array a[i].
Step 5: Initialize avail[i]=0 to check page hit.
Step 6: Replace the page with circular queue, while replacing check page availability in the frame.
Step 7: Place avail[i]=1 if page is placed in the frame.
Step 8: Count page faults.
Step 7: Print the results and Stop the process.
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,a[50],
frame[10],no,k,avail,count=0;
clrscr();
printf("\nenter the number of pages\n");
scanf("%d",&n);
printf("\n enter the page number:\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("\n enter the number of frames");
scanf("%d",&no);
for(i=0;i<no;i++)
frame[i]=-1;
j=0;
printf("\t reference string \t page frames\n");
for(i=1;i<=n;i++)
{
printf("%d\t",a[i]); avail=0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
avail=1;
if(avail==0)
{ frame[i]=a[i];
j=(j+1)%no; count++;
for(k=0;k<no;k++)
printf("%d\t",frame[k]);
}
printf("\n");
}
printf("Page fault is %d",count); getch();
}
OUTPUT:
15.a. Write a c program to implement LRU page replacement algorithm.
AIM:
To write a C program to execute the Least Recently Used page replacement algorithm.
ALGORITHM:
Step 1: Start the process.
Step 2: Declare the size.
Step 3: Get the number of pages to be inserted.
Step 4: Get the value.
Step 5: Declare counter and stack.
Step 6: Select the least recently used page by counter value.
Step 7: Stack them according the selection.
Step 8: Display the values.
Step 9: Stop the process.

CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int q[20],p[50],c=0,c1,d,f,i,j,k=0,n,r,t,b[20],c2[20];
clrscr();
printf("enter no of pages");
scanf("%d",&n);
printf("enter the reference stirng");
for(i=0;i<n;i++)
scanf("%d",&p[i]);
printf("enter the no of frames");
scanf("%d",&f);
q[k]=p[k];
printf("\n\t%d\n",q[k]);
c++;
k++;
for(i=1;i<n;i++)
{
c1=0;
for(j=0;j<f;j++)
{
if(p[i]!=q[j])
c1++;
}
if(c1==f)
{
c++;
if(k<f)
{
q[k]=p[i]; k++;
}
else
{
for(j=0; j<k;j++)
printf("\t%d", q[j]);
printf("\n");
for(r=0;r<f; r++)
{
c2[r]=0;
for(j=i-1;j<n; j--)
{
if(q[r]!=p[j])
c2[r]++;
else
}
}
break;
for(r=0;r<f; r++)
b[r]=c2[r];
for(r=0;r<f; r++)
{
for(j=r; j<f; j++)
{
if(b[r]>b[j])
{
t=b[r]; b[r]=b[j]; b[j]=t;
}
}
}
for(r=0;r<f; r++)
{
if(c2[r]==b[0])
q[r]=p[i];
printf("\t%d",q[r]);
}
printf("\n");
}
}
}
printf("\n the no of page faults%d",c);
getch();
}
OUTPUT:

}
SYSTEM CALLS

1.Write a program to implement system call fork() and Wait().


2.Write a program to implement system call wait() and exit().
3.Write a program to implement system call getpid().

AIM :

To write the program to create a Child Process using system call fork(),exit().

ALGORITHM :

Step 1 : Declare the variable pid.


Step 2 : Get the pid value using system call fork().
Step 3 : If pid value is less than zero then print as “Fork failed”.
Step 4 : Else if pid value is equal to zero include the new process in the system’s file using execlp
system call.
Step 5 : Else if pid is greater than zero then it is the parent process and it waits till the child completes
using the system call wait()
Step 6 : Then print “Child complete”.

SYSTEM CALLS USED:

1. fork( )

Used to create new processes. The new process consists of a copy of the address space of the original
process. The value of process id for the child process is zero, whereas the value of process id for the
parent is an integer value greater than zero.
Syntax : fork( )

2.execlp( )

Used after the fork() system call by one of the two processes to replace the process‟ memory space
with a new program. It loads a binary file into memory destroying the memory image of the program
containing the execlp system call and starts its execution. The child process overlays its address space
with the UNIX command /bin/ls using the execlp system call.
Syntax : execlp( )

3. wait( )

The parent waits for the child process to complete using the wait system call. The wait system call
returns the process identifier of a terminated child, so that the parent can tell which of its possibly many
children has terminated.
Syntax : wait( NULL)

4. exit( )
A process terminates when it finishes executing its final statement and asks the operating system to
delete it by using the exit system call. At that point, the process may return data (output) to its parent
process (via the wait system call).
Syntax: exit(0)

PROGRAM CODING :
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
void main(int argc,char *arg[])
{
int pid;
pid=fork();
if(pid<0)
{
printf("fork failed");
exit(1);
}
else if(pid==0)
{
execlp("whoami","ls",NULL);
exit(0);
}
else
{
printf("\n Process id is -%d\n",getpid());
wait(NULL);
exit(0);
}
}
OUTPUT:
[studentcc2]$ cc prog4a.c
[student@cc2]$ ./a.out

RESULT:
Thus the program was executed and verified successfully

SHELL PROGRAM
1. Write a shell program to find the given number is odd or even
ALGORITHM:
STEP 1: Start the program.
STEP 2: Read the value of n.
STEP 3: Calculate „r=expr $n%2‟.
STEP 4: If the value of r equals 0 then print the number is even
STEP 5: If the value of r not equal to 0 then print the number is odd.

PROGRAM:

echo "Enter the Number"


read n
r=`expr $n % 2`
if [ $r -eq 0 ]
then
echo "$n is Even number"
else
echo "$n is Odd number"
fi

2. Write a shell program to find the given year is leap year or not.

ALGORITHM:
STEP 1: Start the program.
STEP 2: Read the value of year.
STEP 3: Calculate “b=expr $y%4‟.
STEP 4: If the value of b equals 0 then print the year is a leap year
STEP 5: If the value of r not equal to 0 then print the year is not a leap year.

PROGRAM:

echo "Enter the year"


read y
b=`expr $y % 4`
if [ $b -eq 0 ]
then
echo "$y is a leap year"
else
echo "$y is not a leap year"
fi

3. Write a shell program to find the factorial of a number.

ALGORITHM:

STEP 1: Start the program.


STEP 2: Read the value of n.
STEP 3: Calculate „i=expr $n-1‟.
STEP 4: If the value of i is greater than 1 then calculate „n=expr $n \* $i‟ and „i=expr $i – 1‟
STEP 5: Print the factorial of the given number.

PROGRAM:

echo "Enter a Number"


read n
i=`expr $n - 1`
p=1
while [ $i -ge 1 ]
do
n=`expr $n \* $i` i=`expr $i - 1`
done
echo "The Factorial of the given Number is $n"

4. Write a shell program to swap the two numbers.

ALGORITHM:
STEP 1: Start the program.
STEP 2: Read the value of a,b.
STEP 3: Calculate the swapping of two values by using a temporary variable temp.
STEP 4: Print the value of a and b.

PROGRAM:
echo "Enter Two Numbers"
read a, b
temp=$a
a=$b
b=$temp
echo "after swapping"
echo $a $b

UNIX COMMANDS

AIM:
To study about the basics of UNIX Commands.

FILE MANIPULATION COMMANDS

Command : cat>
Purpose : It is used to create a new file.
Syntax : cat>file name
Example : $ cat>program

Command : cat
Purpose : It is used to display the contents of the file.
Syntax : cat <file name>
Example : $ cat program

Command vi
Purpose : It is used to edit the file.
Syntax : vi <file name>
Example : $ vi program

Command : more
Purpose : It is used to display the contents of the file on the screen at a time.
Syntax : more <file name>
Example : $ more program

Command : wc
Purpose : It is used to count the number of lines, words and characters in a file or group of
files.
Syntax : wc [options] <file name >
Example : $ wc –l program
Command : file
Purpose : It is used to determine the type of the file.
Syntax : file <file name>
Example : $ file program

Command : spell
Purpose : It is used to find the spelling errors in the file.
Syntax : spell [options] <file name >
Example : $ spell -b program

Command : split
Purpose : It is used to split the given file into smaller pieces of given size.
Syntax : split –l size <file name> <prefix of splitted file name>
Example : $ split –l 2 program f
Note : The splitted file will be in the filenames faa, fab, fac and so on.
Command : cp
Purpose : It is used to copy one or more files.
Syntax : cp <source file name> <destination file name> cp –r <source dir name>
<destination dir name>
Example : $ cp program ; $ cp –r dir1 dir2;

Command : mv
Purpose : It is used to move a file within a directory with different names and also used to
move a file to different directory with its original name.
Syntax : mv <source file name> <destination file name>
Example : $ mv program

Command : rm
Purpose : It is used to remove a file or a directory from the disk.
Syntax : rm <file name>; rm –r <dir name>
Example : $ rm program; $ rm –r dir1;

GENERAL PURPOSE COMMANDS


Command : banner
Purpose : It is used to display its argument in large letters.
Syntax : banner <string>
Example : $ banner BOOM

Command : who
Purpose : It is used to get the information about all the users currently working in the
system.
Syntax : who
Example : $ who

Command : whoami
Purpose : It is used to know in which terminal the user is currently logged on.
Syntax : whoami
Example : $ whoami

Command : exit
Purpose : It is used to exit from UNIX.
Syntax : exit
Example : $ exit

Command : date
Purpose : It is used to display the system date and time.
Syntax : date
Example : $ date

Command : cal
Purpose : It prints the calender for the specified year and month.
Syntax : cal <month> <year>
Example : $ cal 05 2003

Command : id
Purpose : It is used to display the login name.

Syntax : id
Example : $ id

Command : clear
Purpose : It is used to clear the screen.
Syntax : clear
Example : $ clear

Command : uname
Purpose : It is used to display the details about the OS in which we are working.
Syntax : uname [options] Options: a, n, s, r, v, m, p, o, I
Example : $ uname –n

Command : tty
Purpose : It is used to know the terminal name on which we work.
Syntax : tty
Example : $ tty

Command : pwd
Purpose : It is used to display the absolute pathname of current working directory.
Syntax : pwd
Example : $ pwd

Command : bc
Purpose : It is used to perform simple mathematical calculations.
Syntax : echo “expression” | bc
Example : $ echo “3+5* 8” | bc

Command : echo
Purpose : It echoes the argument on the standard output device.
Syntax : echo <string> Example : $ echo BOOM

Command : ls
Purpose : The ls command lists all files in the directory that match the name. If name is left
blank, it will list all of the files in the directory.
Syntax : ls [options] [name]
Example : $ ls
Options Description
-a Displays all files.
-c Displays files by file timestamp.
-d Displays only directories.
-l Displays the long format listing.
-m Displays the names as a comma-separated list.
-p Displays directories with /
-r Displays files in reverse order.
-1 Displays each entry on a line.

Command : man
Purpose : It gives details about the unix commands.
Syntax : man <command name>
Example : $ man echo

COMMAND GROUPING & FILTER COMMANDS


Command : head
Purpose : It is used to display the top portion of the file. Head prints the first N number of
data of the given input. By default, it prints first 10 lines of each given file.
Syntax : head [options] <file name>
Example : $ head -5 program

Command : tail
Purpose : It is used to display the bottom portion of the file.
Syntax : tail [options] <file name>
Example : $ tail –5 program
Command : pr
Purpose : It is used to display the contents of the file by separating them into pages and each
page begins with the header information.
Syntax : pr [options] <file name >
Example : $ pr program

Command : cut
Purpose : It is used to extract selected fields or columns from each line of one or more files
and display them on the standard output device.
Syntax : cut [options] <file name>
Example : $ cut –c5 program

Command : paste
Purpose : It concatenates the line from each input file column by column with tab characters
in between them.
Syntax : paste <file name1> <file name2>
Example : $ paste f1 f2

Command : join
Purpose : It is used to extracts common lines from two sorted files and there should be the
common field in both file.
Syntax : join [options] <file name1> <file name2>
Example : $ join –a1 f1 f2

Command : uniq
Purpose : It compares adjacent lines in the file and displays the output by eliminating
duplicate adjacent lines in it.
Syntax : uniq [options] <file name>
Example : $ uniq -c program

Command : sort
Purpose : It sorts one or more files based on ASCII sequence and also to merge the file.
Syntax : sort [options] <file name>
Example : $ sort -r program
Command : nl
Purpose : It is used to add line numbers to the lines in the file.
Syntax : nl [options] [filename]
Example : $ nl program

Command : tee
Purpose : It is used to read the contents from standard input or from output of another
command and reproduces the output to both in standard output and direct into output to one or
more files.
Syntax : <command name> | tee <file name>
Example : $ date | tee dat.txt
Command : grep
Purpose : It is used to search the specified pattern from one or more files.
Syntax : grep [options] <pattern> <file name>
Example : $ grep “anand” program

Options Description
-b Display the block number at the beginning of each line.
-c Display the number of matched lines.
-l Display the filenames, but do not display the matched lines
-n Display the matched lines and their line numbers.
-v Display all lines that do NOT match.

Command : mkdir
Purpose : It is used to create new directory or more than one directory.
Syntax : mkdir <directory name>
Example : $ mkdir student

Command : rmdir
Purpose : It is used to remove the directory if it is empty.
Syntax : rmdir <directory name>
Example : $ rmdir student

Command : cd
Purpose : It is used to change the control from one working directory to another specified
directory.
Syntax : cd <directory name>
Example : $ cd student

Command : cd ..
Purpose : It is used to quit from current directory and move to the previous directory.
Syntax : cd ..
Example : $ cd ..
PROCESS COMMANDS
Command : echo $$
Purpose : It is used to display the process number of the current shell.
Syntax : echo $$
Example : $ echo $$

Command : ps
Purpose : It is used to display the attributes of a process.
Syntax : ps
Example : $ ps
$ ps –f ( Display the ancestry of a process )
$ ps –u ( Display the activities of a user )
$ ps –a ( Lists processes of all users but not the system processes )

Command :&
Purpose : It is shell operator which is used to run a process in the background.
Syntax : <command> &
Example : $ sort emp.txt &

Command : nohup
Purpose : It permits the execution of the process even after the user has logged out.
Syntax : nohup <command>
Example : $ nohup sort emp.txt (result is available on nohup.out )
Command : kill
Purpose : It is used to terminate the process.
Syntax : kill <PID>
Example : $ kill 105

Command : at
Purpose : It is used to execute the process at the time specified.
Syntax : echo at <time>
Example : $ at 14:08 (or) $ at 3 PM (or) $ at 4 :50 AM
SAVE AND EXIT COMMANDS
Press <ESC> and then
Command Description
:w Save the file.
:wq Save and quit.
:q Quit.
:sh Exit from shell programming.
:: Insert into left of the cursor in the file.
:i Insert the text in the begining of the line.
:A Insert the text in the left of the line.
:a Insert the text in the right of the line.
:r Overwrite the text at the right of the cursor.
:s Replace a single character.
:dd Delete a line.

RESULT:

Thus the basic UNIX Commands are studied and executed Successfully.

You might also like