You are on page 1of 26

//RAGHAV GUPTA //ROLL NO.

-0809513040

OPERATING SYSTEM
1> WHAT IS LINUX SHELL? Computer understand the language of 0's and 1's called binary language. In early days of computing, instruction are provided using binary language, which is difficult for all of us, to read and write. So in Os there is special program called Shell. Shell accepts your instruction or commands in English (mostly) and if its a valid command, it is pass to kernel. Shell is a user program or it's environment provided for user interaction. Shell is an command language interpreter that executes commands read from the standard input device (keyboard) or from a file. Shell is not part of system kernel, but uses the system kernel to execute programs, create files etc. Several shell available with Linux: ..Bourne shell ..C shell ..Bourne-Again shell ..Korn shell To find all available shells in your system type following command: $ cat /etc/shells. 2>WHAT IS SHELL SCRIPT ? Normally shells are interactive. It means shell accept command from us (via keyboard) and execute them. But if we use command one by one (sequence of 'n' number of commands) , we can store this sequence of command to text file and tell the shell to execute this text file instead of entering the commands. This is know as shell script. Shell script defined as: "Shell Script is series of command written in plain text file. Shell script is just like batch file is MS-DOS but have more power than the MSDOS batch file." ECHO COMMAND: we use echo command to display text or value of a variable....... EXAMPLE: ..create a file using vi editor vi him,where vi stands for 'visual'. ..type the following code echo mynameis read name echo $xyz

where $ is space holder.. ..execute the program sh him ..output mynameis xyz.

3> USING WHO COMMAND IN LINUX. If we want to know which users are currently logged in to our Linux system, which console they're using, and the date and time we logged in, issue the who command. 4>USING WHO AM I COMMAND IN LINUX.

If we want to know the ip address of machine currently in use into our linux system,we use the who am i command..... 5>USING THE IFCONFIG COMMAND IN LINUX If we want to know the details of the system ,we use the ifconfig command..... currently acting as server

//RAGHAV GUPTA //ROLL NO.-0809513040

FORK :-

In software engineering, a project fork happens when developers take a legal copy of source code from one software package and start independent development on it, creating a distinct piece of software. Free and open source software is that which, by definition, may be forked from the original development team without prior permission without violating any copyright law. However, licensed forks of proprietary software (e.g. Unix) also happen. The term fork in this context derives from the use of the term in computer operating systems (especially Unix) where it refers to the creation of a copy of a running program (process) by forking a process, which creates two identical processes (like cell division in living things); the two are then independent, and may proceed to do different tasks, as the program dictates. The independent development of two software projects cloned from the same source code is analogous to Unix forking. The term fork comes from the POSIX standard for portable operating operating systems. Here, fork() is a system call which a process uses to create a copy of itself. After the fork two copies of the process exist: a parent and a child. Typically, the new child process will then overwrite its image in memory with some other program image using the execv() or variants. This fork and execv() calls form the core of shell programs. When a user executes a new command such as more the shell forks(), and then replaces the child process image with the image of the more program through the execv() system call. The analogy with forking the source code in a software project is analogous.

//RAGHAV GUPTA

//ROLL NO.-0809513040

Greater :echo enter the no read no if test $ no -ge 10 then echo $ no is greater than 10 else echo $ no is smaller than 10 fi

SHELL :On system with multiple command interpreters to choose from ,the interpreters are known as shells. For example , on UNIX and linux systems a user may choose among several different shells ,including the Bourne shell ,C shell ,Bourne-Again shell , Korn shell, and others.

//RAGHAV GUPTA

//ROLL NO.-0809513040

Write program using shell
vi him echo my name is read name echo $name

//RAGHAV GUPTA //ROLL NO.-0809513040

//Write program using fork
<<fork()>>

main() { fork(); printf("hello world"); }

//RAGHAV GUPTA //ROLL NO.-0809513040

Write program using wait and fork
main { int i; i=fork(); if(i!=0) { printf("parent=%d", wait(); } else { printf("child=%d", ); } );

//RAGHAV GUPTA //ROLL NO.-0809513040

/* program of FCFS */

#include<stdio.h> #include<conio.h> main() { int i,b[10],wt[10],tut[10],awt,atut,n,swt=0,stut=0; printf("ENTER THE NO OF JOBS:-"); scanf("%d",&n); printf("ENTER BURST TIME:-"); for(i=1;i<=n;i++) scanf("%d",&b[i]); wt[1]=0; for(i=2;i<=n;i++) wt[i]=wt[i-1]+b[i-1]; for(i=1;i<=n;i++) tut[i]=wt[i]+b[i]; for(i=1;i<=n;i++) { swt=swt+wt[i]; stut=stut+tut[i]; } atut=(stut/n); awt=(swt/n); printf("AVG WAITING TIME=%d\n",awt); printf("AVG TURNOVER TIME =%d\n",awt);

}

//RAGHAV GUPTA //ROLL NO.-0809513040

/* program of SJF*/

#include<stdio.h> #include<conio.h> main() { int i,b[10],wt[10],tut[10],awt,atut,n,swt=0,stut=0,j,temp; printf("ENTER THE NO OF JOBS:-"); scanf("%d",&n); printf("ENTER BURST TIME:-"); for(i=1;i<=n;i++) scanf("%d",&b[i]); for(j=1;j<=n;j++) { if(b[i]>b[j]) { temp=b[i]; b[i]=b[j]; b[j]=temp; } } wt[1]=0; for(i=2;i<=n;i++) wt[i]=wt[i-1]+b[i-1]; for(i=1;i<=n;i++) tut[i]=wt[i]+b[i]; for(i=1;i<=n;i++) {

swt=swt+wt[i]; stut=stut+tut[i]; } atut=(stut/n); awt=(swt/n); printf("AVG WAITING TIME=%d\n",awt); printf("AVG TURNOVER TIME =%d\n",awt); }

OUTPUT:ENTER NO OF JOBS:-4 ENTER BURST TIME:-6 0 1 4 6 Avg waiting time=3 Avg turnover time=6

//RAGHAV GUPTA //ROLL NO.-0809513040

/* program of PRIORITY*/

#include<stdio.h> #include<conio.h>

main() { int i,b[10],wt[10],tut[10],pt[10],temp1; float awt,atut,n,swt=0,stut=0; printf("ENTER THE NO OF JOBS:-"); scanf("%d",&n); printf("ENTER BURST TIME:-"); for(i=1;i<=n;i++) scanf("%d",&b[i]); printf("\n enter no of priority:-"); for(j=1;j<=n;j++) { scanf("%d",&pt[i]); } for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(pt[i]>pt[j]) { temp=b[i]; b[i]=b[j]; b[j]=temp; } temp1=pt[i]; pt[i]=pt[j];

pt[j]=temp1; }}} wt[1]=0; for(i=2;i<=n;i++) wt[i]=wt[i-1]+b[i-1]; for(i=1;i<=n;i++) tut[i]=wt[i]+b[i]; for(i=1;i<=n;i++) { swt=swt+wt[i]; stut=stut+tut[i]; } atut=(stut/n); awt=(swt/n); printf("AVG WAITING TIME=%f\n",awt); printf("AVG TURNOVER TIME =%f\n",awt); }

OUTPUT:ENTER NO OF JOBS=4 Enter burst time=10 1 4 5 2

ENTER priority=3 1 4 5 2

Avg waiting time=8.200

Avg turnover time=12.00

//RAGHAV GUPTA //ROLL NO.-0809513040

//PROGRAM OF ROUND ROBIN:#include<stdio.h> #include<conio.h> struct{ int bt,wt,cst,rbt,finish; } pd[10];

void main() { int i,q,n,twt=0,time=0,avg=0,tbt=0; float awt; clrscr(); printf("Enter the quantum"); scanf("%d",&q); printf("Enter the no. of jobs "); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter the burst time"); scanf("%d",&pd[i].bt); pd[i].rbt=pd[i].bt; pd[i].wt=0; pd[i].cst=0; pd[i].finish=0; tbt=tbt+pd[i].bt; } while(tbt) { for(i=0;i<n;i++) { if(pd[i].finish==1) {

continue; } time=q;

if(pd[i].rbt<=q) { time=pd[i].rbt; pd[i].finish=1; } pd[i].rbt=pd[i].rbt-time; printf("pd[i].rbt : %d\n",pd[i].rbt); pd[i].wt=pd[i].wt+twt-pd[i].cst; printf("pd[i].wt:%d ,twt:%d ,pd[i].cst:%d\n",pd[i].wt,twt,pd[i].cst); twt=twt+time; printf("twt : %d\n",twt); pd[i].cst=twt; printf("pd[i].cst : %d\n",pd[i].cst); tbt=tbt-time; } } for(i=0;i<n;i++) { printf("waiting of jobs%d=%d\n",i,pd[i].wt); avg=avg+pd[i].wt; } awt=(float)avg/n;

printf("avg waiting time: %f",awt); getch(); }

OUTPUT:Enter the quantum 3 Enter the no of jobs 2 Enter the Burst Time 3 Enter the burst time 3 Pd[i].rbt : 0 Pd[i].wt: 0 , twt :0 ,pd[i].cst : 0 Twt : 3 Pd[i].cst : 3 Pd[i].rbt : 0 Pd[i].wt : 3, twt : 3 ,pd[i].cst : 0 Twt : 6 Pd[i].cst : 6 Waiting of jobs0=0 Waiting of job1=3 Avg waiting time : 1.500000

//RAGHAV GUPTA //ROLL NO.-0809513040

PROGRAM TO IMPLEMENT BANKER’S ALGORITHM:#include<stdio.h> #define true 1 #define false 0 main() { int Safe[10],avail[6],need[10][10],alloc[10][10],max[10][10],finish[10],temp; int i,j,k,m,n,x,safe; safe=0; printf("\n********************************START******************************");

printf("\nEnter number of process:"); scanf("%d",&n); printf("Enter number of resources:"); scanf("%d",&m); printf("Enter max Process-resource matrix(%d x %d):\n",n,m); for(i=0;i<n;i++) { Safe[i]=-1; finish[i]=false; for(j=0;j<m;j++) { scanf("%d",&max[i][j]); } } printf("Enter avilable resource vector(length %d):",m); for(i=0;i<m;i++) { scanf("%d",&avail[i]); } printf("Enter allocation matrix:(%d x%d):\n",n,m); for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%d",&alloc[i][j]); }

} printf("Process resource need matrix is:"); for(i=0;i<n;i++) { printf("\n"); for(j=0;j<m;j++) { need[i][j]=max[i][j]-alloc[i][j]; printf("%d",need[i][j]); } } for(i=0;i<n && safe!=n;i++) { printf("\n============================================= =================="); printf("\nCheck for Process P%d",i); for(j=0;j<n && safe!=n;j++) { if(!finish[j]) { printf("\n Process P%d is not finished yet.resouce availabe?",j); temp=true; for(k=0;k<m;k++) { if(need[j][k]>avail[k]) { printf("\nRequired Resouce are not available.");

temp=false; break; } } if(temp) { printf("\n Required resources are available.Process finished."); Safe[safe]=j; safe++; finish[j]=true; for(x=0;x<m;x++) { avail[x]+=alloc[j][x]; } } } } } printf("\n============================================= ====================="); printf("\nProcess finished in following order:\n"); for(i=0;i<n;i++) { if(Safe[i]>=0) { printf("%d",Safe[i]); }

else { printf("NA"); } } if(safe==n) { printf("\nResult:Safe state"); } else { printf("\nResult :Unsafe state"); } printf("\n************************************END*******************************"); return 0; }

//RAGHAV GUPTA //ROLL NO.-0809513040

//Program to implement Peterson algo
#include<stdio.h> #include<conio.h> #define ture 1 #define false 0; int flag[2]; int turn; void program0() { flag[0]=turn; turn=1; while(flag[1]&&turn==1) { printf("do nothing"); }

printf("program0 in cs"); flag[0]=false; } void program1() { flag[1]=turn; turn=0; while(flag[0]&&turn==0) { printf("do nothing"); } printf("program1 in cs"); flag[1]=false; } void main() { clrscr(); flag[0]=false; flag[1]=false; printf("enter the turn"); scanf("%d",&turn); if (turn==1) program1(); else program0(); getch();

}

OPERATING SYSTEM PRACTICAL FILE

NAME : RAGHAV GUPTA CLASS: ST-IT ROLL NO.-0809513040 CLASS ROLL NO.-32