Screenshot 2024-06-12 at 8.01.22 AM
Screenshot 2024-06-12 at 8.01.22 AM
Experiment 1:
Study of Unix/Linux general purpose utility command list: man, who, cat, cd, cp, ps, ls,
mv, rm, mkdir, rmdir, echo, more, date, time, kill, history, chmod, chown, finger, pwd, cal,
logout, shutdown.
1. man - view manual pages for UNIX commands
Syntax: man [-s section] item
$ man cat
2. who - displays the list of users logged presently
Syntax: who [option]… [file][arg1]
$ who
3. cat - concatenate files and show contents to the standard output
Syntax: cat [option]…[file]
$ cat >
file1
hello
4. cd - change directory
Syntax: cd [option] directory
$ cd dir1
5. cp - copy files
Syntax: cp [option] source destination
$ cp file1 file2
6. ps - Reports process status
Syntax: Ps [options]
$ ps
7. ls - List files & directories
Syntax: ls [option] [file]
$ ls
8. mv - Rename or move files & directories to another location
Syntax: mv [option] source destination
$ mv file1 file2
9. rm - removes files & directories
Syntax: rm [option]…[file]
$ rm file1
10. mkdir - makes new directory
Syntax: mkdir [option] directory
$ mkdir dir1
11. rmdir - removes directory
Experiment 2:
Study of Bash shell, Bourne shell and C shell in Unix/Linux operating system.
What Is a Shell?
A shell is a program that provides an interface between a user and an operating system (OS)
kernel.
An OS starts a shell for each user when the user logs in or opens a terminal or console
window. A kernel is a program that:
• Controls all computer operations.
• Coordinates all executing utilities
• Ensuresthat executing utilities do not interfere with each other or consume all system
resources.
• Schedules and manages all system processes.
By interfacing with a kernel, a shell provides a way for a user to execute utilities and programs.
Types of Shell
Experiment 3:
▪ This is a virtual filesystem with text information about system resources. For example:
/proc/uptime
7. /var – Variable Files
▪ var stands for variable files.
▪ Content of the files that are expected to grow can be found under this directory.
▪ This includes — system log files (/var/log); packages and database files (/var/lib);
emails (/var/mail); print queues (/var/spool); lock files (/var/lock); temp files needed
across reboots (/var/tmp);
8. /tmp – Temporary Files
▪ Directory that contains temporary files created by system and users.
▪ Files under this directory are deleted when system is rebooted.
9. /usr – User Programs
▪ Contains binaries, libraries, documentation, and source-code for second level programs.
▪ /usr/bin contains binary files for user programs. If you can’t find a user binary under
/bin, look under /usr/bin. For example: at, awk, cc, less, scp
▪ /usr/sbin contains binary files for system administrators. If you can’t find a system
binary under /sbin, look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel
▪ /usr/lib contains libraries for /usr/bin and /usr/sbin
▪ /usr/local contains users programs that you install from source. For example, when you
install apache from source, it goes under /usr/local/apache2
10. /home – Home Directories
▪ Home directories for all users to store their personal files.
▪ For example: /home/john, /home/nikita
11. /boot – Boot Loader Files
▪ Contains boot loader related files.
▪ Kernel initrd, vmlinux, grub files are located under /boot
▪ For example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic
12. /lib – System Libraries
▪ Contains library files that supports the binaries located under /bin and /sbin
▪ Library filenames are either ld* or lib*.so.*
▪ For example: ld-2.11.1.so, libncurses.so.5.7
13. /opt – Optional add-on Applications
▪ opt stands for optional.
▪ Contains add-on applications from individual vendors.
▪ Add-on applications should be installed under either /opt/ or /opt/ sub-directory.
14. /mnt – Mount Directory
▪ Temporary mount directory where sysadmins can mount filesystems.
15. /media – Removable Media Devices
Experiment 4:
Write a C program to emulate the UNIX ls –l Command.
Program:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
int main()
{
int pid; //process id
pid = fork(); //create another process
if ( pid < 0 )
{ //fail
printf(“\nFork failed\n”);
exit (-1);
}
else if ( pid == 0 )
{ //child
execlp ( “/bin/ls”, “ls”, “-l”, NULL ); //execute ls
}
else
{ //parent
wait (NULL); //wait for child
printf(“\nchild complete\n”);
exit (0);
}
}
Output:
guest-glcbIs@ubuntu:~$gcc –o lsc.out lsc.c
guest-glcbIs@ubuntu:~$./lsc.out
total 100
-rwxrwx—x 1 guest-glcbls guest-glcbls 140 2012-07-06 14:55 f1
drwxrwxr-x 4 guest-glcbls guest-glcbls 140 2012-07-06 14:40 dir1
child complete
Experiment 5:
Write a C program that illustrates how to execute two commands concurrently with a
command pipe. Ex: - ls –l | sort
Program:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
int main()
{
int pfds[2];
char buf[30];
if(pipe(pfds)==-1)
{
perror("pipe failed");
exit(1);
}
if(!fork())
{
close(1);
dup(pfds[1];
system (“ls –l”);
}
else
{
printf("parent reading from pipe \n");
while(read(pfds[0],buf,80))
printf("%s \n" ,buf);
}
}
Output:
[student@gcet ~]$ vi pipes2.c
[student@gcet ~]$ cc pipes2.c
[student@gcet ~]$ ./a.out
Parent reading from pipe
Total 24
-rwxrwxr-x l student student 5563Aug 3 10:39 a.out
-rw-rw-r—l
Student student 340 jul 27 10:45 pipe2.c
-rw-rw-r—l student student
Pipes2.c
-rw-rw-r—l student student 401 34127 10:27 pipe2.c
student
Experiment 6:
Multiprogramming Memory management Implementation of
fork(),wait(),exec() and exit(),system calls
FORK():
PROGRAM:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
void forkexample()
{
if (fork() == 0)
printf("Hello from Child!\n");
else
printf("Hello from Parent!\n");
}
int main()
{
forkexample();
return 0;
}
OUTPUT:
PROGRAM:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/wait.h>
int main()
{
pid_t pid;
int ret = 1;
int status;
pid = fork();
if (pid == -1)
{
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<unistd.h>
int main()
{
pid_t cpid;
if (fork()== 0)
exit(0);
else
cpid = wait(NULL);
printf("Parent pid = %d\n", getpid());
printf("Child pid = %d\n", cpid);
return 0;
}
EXIT():
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf("START");
exit(0);
printf("End of program");
}
OUTPUT:
START
FCFS:
#include<stdio.h>
void main()
{
int i,n,sum,wt,tat,twt,ttat; int t[10];
float awt,atat;
clrscr();
printf("Enter number of processors:\n"); scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter the Burst Time of the process %d",i+1);
scanf("\n %d",&t[i]);
}
printf("\n\n FIRST COME FIRST SERVE SCHEDULING ALGORITHM \n");
printf("\n Process ID \t Waiting Time \t Turn Around Time \n");
printf("1 \t\t 0 \t\t %d \n",t[0]);
sum=0;
twt=0;
ttat=t[0];
for(i=1;i<n;i++)
{
sum+=t[i-1];
wt=sum;
tat=sum+t[i];
twt=twt+wt;
ttat=ttat+tat;
printf("\n %d \t\t %d \t\t %d",i+1,wt,tat);
printf("\n\n");
}
awt=(float)twt/n;
atat=(float)ttat/n;
printf("\n Average Waiting Time %4.2f",awt);
getch();
OUTPUT:
Enter number of processors:
3
Enter the Burst Time of the process: 124 Enter the Burst Time of the process: 23 Enter the Burst Time of the
process: 33
FIRST COME FIRST SERVE SCHEDULING ALGORITHM
1 0 24
2 24 27
3 27 30
Average Waiting Time: 17.00 Average Turnaround Time: 27.00
for(j=i+1;j<n;j++)
if(ptime[i]>ptime[j])
temp = ptime[i];
ptime[i] = ptime[j];
ptime[j] = temp;
ptemp = process[i];
process[i] = process[j];
process[j] = ptemp;
}
}
wtime[0]=0;
for(i=1;i<n;i++)
{
wtime[i]=wtime[i-1]+ptime[i-1];
total=total+wtime[i];
}
avg=(float)total/n;
printf("\nP_ID\t P_TIME\t W_TIME\n");
for(i=0;i<n;i++)
printf("%d\t %d\t %d\n",process[i],ptime[i],wtime[i]);
printf("\nTotal Waiting Time: %d \nAverage Waiting Time: %f", total, avg); getch();
}
OUTPUT:
Enter number of Processes: 4 Enter Process 1 ID: 1
Enter Process 1 Time: 6
Enter Process 2 ID: 2
Enter Process 2 Time: 8
Enter Process 3 ID: 3
Enter Process 3 Time: 7
Enter Process 4 ID: 4
Enter Process 4 Time: 3
P_I D P_TIM E W_TIM E
4 3 0
1 6 3
3 7 9
2 8 16
Total Waiting Time: 28
Average Waiting Time: 7.000000
.priority Program:
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j,n,tat[10],wt[10],bt[10],pid[10],pr[10],t,twt=0,ttat=0; float awt,atat;
clrscr();
scanf ("%d",&pr[i]);
}
for (i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if (pr[i] > pr[j] )
{
t = pr[i];
pr[i] = pr[j];
pr[j] = t;
t = bt[i];
bt[i] = bt[j];
bt[j] = t;
t = pid[i];
pid[i] = pid[j];
pid[j] = t;
}
}
tat[0] = bt[0];
wt[0] = 0;
for (i=1;i<n;i++)
{
wt[i] = wt[i-1] + bt[i-1];
tat[i] = wt[i] + bt[i];
}
printf("\n \n");
printf("Pid\t Priority\tBurst time\t WaitingTime\tTurnArroundTime\n");
printf("\n \n");
for(i=0;i<n;i++)
{
printf("\n%d\t\t%d\t%d\t\t%d\t\t%d",pid[i],pr[i],bt[i],wt[i],tat[i]);
}
for(i=0;i<n;i++)
{
ttat = ttat+tat[i];
twt = twt + wt[i];
}
awt = (float)twt / n;
atat = (float)ttat / n;
printf("\n\nAvg.Waiting Time: %f\nAvg.Turn Around Time: %f\n",awt,atat);
getch();
}
OUTPUT:
-----------PRIORITY SCHEDULING--------------
Enter the No of Process: 5
Enter the Burst time of Pid_0: 10
Enter the Priority of Pid_0: 3
Enter the Burst time of Pid_1: 1
Enter the Priority of Pid_1: 1
Enter the Burst time of Pid_2:
2 Enter the Priority of Pid_2:
4 Enter the Burst time of Pid_3: 1
Enter the Priority of Pid_3: 5
Enter the Burst time of Pid_4: 5
Enter the Priority of Pid_4: 2
--------------------------------------------------------------------------------------------------
1 1 1 0 1
4 2 5 1 6
0 3 10 6 16
2 4 2 16 18
3 5 1 18 19
--------------------------------------------------------------------------------------------------
Avg.Waiting Time: 8.200000
Avg.Turn around Time: 12.000000
a) Round Robin
Program: #include<stdio.h>
#include<conio.h>
main()
{
int st[10],bt[10],wt[10],tat[10],n,tq; int i,count=0,swt=0,stat=0,temp,sq=0;
float awt=0.0,atat=0.0;
clrscr();
printf("Enter number of processes:");
scanf("%d",&n);
printf("Enter burst time for sequences:");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
st[i]=bt[i];
}
printf("Enter time quantum:");
scanf("%d",&tq);
while(1)
{
for(i=0,count=0;i<n;i++)
{
temp=tq;
if(st[i]==0)
{
count++;
continue;
}
if(st[i]>tq) st[i]=st[i]-tq; else if(st[i]>=0)
{
temp=st[i];
st[i]=0;
}
sq=sq+temp;
tat[i]=sq;
}
if(n==count)
break;
}
for(i=0;i<n;i++)
{
wt[i]=tat[i]-bt[i];
swt=swt+wt[i];
stat=stat+tat[i];
}
awt=(float)swt/n;
atat=(float)stat/n;
printf("Process_no \t Burst time \t Wait time \t Turn around time\n");
for(i=0;i<n;i++)
printf("%d \t%d \t%d \t%d\n",i+1,bt[i],wt[i],tat[i]);
printf("Avg wait time is %f \n Avg turn around time is %f",awt,atat);
getch();
}
OUTPUT:
Enter number of processes: 3
Enter burst time for sequences: 24 3 3
Enter time quantum: 4
1 24 6 30
2 3 4 7
3 3 7 10
Avg wait time is 5.666667
Avg turn around time is 15.666667