Os Lab File.docx

  • Uploaded by: Umang Jain
  • 0
  • 0
  • April 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Os Lab File.docx as PDF for free.

More details

  • Words: 3,976
  • Pages: 47
Ex. No:1 First Come First Serve Date:

Aim To simulate the CPU scheduling algorithm for FCFS (First come First Serve).

Algorithm Step 1: Declare the variables Step 2: Input number of processes Step 3: If n is greater than zero n Step 4: Then input their burst time Step 5: Waiting time for first process is zero Step 6: Compute the waiting time for all the processes Step 7: Calculate the average waiting time Step 8: Display the results Step 9: Stop

Umang Jain [A7605217131]

Page 1

PROGRAM #include #include void main() { clrscr(); int a[20],n,w[20]; cout<<"Enter the no. of jobs:"; cin>>n; for(int i=0;i>a[i]; } w[0]=0; for(i=0;i<=n;i++) { w[i+1]=w[i]+a[i]; } cout<<"GANTT CHART\n"; for(i=0;i
Umang Jain [A7605217131]

Page 2

} avg=avg/n; cout<<"\nAVERAGE WAITING TIME:"<
OUTPUT

RESULT The FCFS program was compiled and executed successfully.

Umang Jain [A7605217131]

Page 3

Ex. No:2 Shortest Job First Date:

Aim To simulate the CPU scheduling algorithm for SJF (Shortest Job First). Algorithm Step 1: Declare the variables Step 2: Input number of processes Step 3: If n is greater than zero n Step 4: Then input their burst time Step 5: Waiting time for first process is zero Step 6: Compute the waiting time for all the processes Step 7: Calculate the average waiting time Step 8: Display the results Step 9: Stop

Umang Jain [A7605217131]

Page 4

PROGRAM #include #include void main() { int i,j,n,ex[20],a[20]; int w[20],temp,s[20]; clrscr(); cout<<"Enter the no. of jobs:"; cin>>n; cout<<endl; for(i=0;i>ex[i];} for(i=0;i
Umang Jain [A7605217131]

Page 5

for(i=0;i #include #include<stdio.h> struct node { char s[10]; int t; int P; }; void main() { clrscr(); int n,i,j; float avg=0; node x; node a[20]; cout<<"Enter the no. of jobs:"; cin>>n; for(i=0;i>a[i].s; cout<<"Enter the time required:"; cin>>a[i].t; cout<<"Enter the priority of the job:"; cin>>a[i].P; } cout<<"INPUT \n"; cout<<"JOB TIME PRIORITY \n"; for(i=0;i=0)) {a[j+1]=a[j]; j=j-1; } a[j+1]=x; } cout<<"PRIORITY SCHEDULING \n"; cout<<"JOB TIME PRIORITY \n"; Umang Jain [A7605217131]

Page 9

for(i=0;i #include void main() { clrscr(); int a[20],r[20],n,e=0,b[20],c=0,w[20],i,j,f=1; int t=3,x[20]; float avg=0; cout<<"Enter the number of jobs:"; cin>>n; for(i=0;i>a[i]; x[i]=0; r[i]=0; b[i]=0; } w[0]=0; cout<<"GANTT CHART\n"; i=0; while(f==1) { if(b[i]==0) { cout<<"| J"<=n) {

Umang Jain [A7605217131]

Page 13

c=0; for(j=0;j Displays the machine id (i.e., name of the system hardware) -n -> Displays the name of the network node. (host name) -r -> Displays the release number of the operating system. -s -> Displays the name of the operating system (i.e.. system name) -v -> Displays the version of the operating system. -a -> Displays the details of all the above five options. SYNTAX: $ uname [option] 13. The ‘finger’ command The finger command with an argument gives you more information about the user. The finger command followed by an argument can give complete information for a user who is not logged onto the system. SYNTAX: $ finger [user-name] EXAMPLE: $ finger periit

1.2 DIRECTORY COMMANDS 1. The ‘pwd’ command: The pwd (print working directory) command displays the current working directory. SYNTAX: $ pwd 2. The ‘mkdir’ command: The mkdir is used to create an empty directory in a disk. SYNTAX: $ mkdir dirname

Umang Jain [A7605217131]

Page 18

EXAMPLE: $ mkdir periit 3. The ‘rmdir’ command: The rmdir is used to remove a directory from the disk. Before removing a directory, the directory must be empty (no files and directories). SYNTAX: $ rmdir dirname EXAMPLE: $ rmdir periit 4. The ‘cd’ command: The cd command is used to move from one directory to another. SYNTAX: $ cd dirname EXAMPLE: $ cd periit 5. The ‘ls’ command: The ls command displays the list of files in the current working directory. SYNTAX: $ ls 1.3 FILE HANDLING COMMANDS 1. The ‘cat’ command: The cat command is used to create a file. SYNTAX: $ cat > filename EXAMPLE: $ cat > periit 2. The ‘Display contents of a file’ command: The cat command is also used to view the contents of a specified file. SYNTAX: $ cat filename 3. The ‘cp’ command: The cp command is used to copy the contents of one file to another and copies the file from one place to another.

Umang Jain [A7605217131]

Page 19

SYNTAX: $ cp oldfile newfile EXAMPLE: $ cp cse ece 4. The ‘rm’ command: The rm command is used to remove or erase an existing file SYNTAX: $ rm filename EXAMPLE: $ rm periit 5. The ‘mv’ command: The mv command is used to move a file from one place to another. It removes a specified file from its original location and places it in specified location. SYNTAX: $ mv oldfile newfile EXAMPLE: $ mv cse eee 6. The ‘file’ command: The file command is used to determine the type of file. SYNTAX: $ file filename EXAMPLE: $ file periit 7. The ‘wc’ command: The wc command is used to count the number of words, lines and characters in a file. SYNTAX: $ wc filename EXAMPLE: $ wc periit 8. The ‘Directing output to a file’ command: The ls command lists the files on the terminal (screen). Using the redirection operator ‘>’ we can send the output to file instead of showing it on the screen. SYNTAX: $ ls > filename EXAMPLE: $ ls > periit

Umang Jain [A7605217131]

Page 20

9. The ‘pipes’ command: The Unix allows us to connect two commands together using these pipes. A pipe ( | ) is an mechanism by which the output of one command can be channeled into the input of another command. SYNTAX: $ command1 | command2 EXAMPLE: $ who | wc -l 10. The ‘tee’ command: While using pipes, we have not seen any output from a command that gets piped into another command. To save the output, which is produced in the middle of a pipe, the tee command is very useful. SYNTAX: $ command | tee filename EXAMPLE: $ who | tee sample | wc -l 11. The ‘Metacharacters of unix’ command: Metacharacters are special characters that are at higher and abstract level compared to most of other characters in Unix. The shell understands and interprets these metacharacters in a special way. * - Specifies number of characters ?- Specifies a single character [ ]- used to match a whole set of file names at a command line. ! – Used to Specify Not EXAMPLE: $ ls r** - Displays all the files whose name begins with ‘r’ $ ls ?kkk - Displays the files which are having ‘kkk’, from the second characters irrespective of the first character. $ ls [a-m] – Lists the files whose names begins alphabets from ‘a’ to ‘m’ $ ls [!a-m] – Lists all files other than files whose names begins alphabets from ‘a’ to ‘m’

Umang Jain [A7605217131]

Page 21

12. The ‘File permissions’ command: File permission is the way of controlling the accessibility of file for each of three users namely Users, Groups and Others. There are three types of file permissions are available, they are r-read w-write x-execute The permissions for each file can be divided into three parts of three bits each.

First three bits

Owner of the file

Next three bits

Group to which owner of the file belongs

Last three bits EXAMPLE: $ ls college -rwxr-xr--

1

Lak

Others std

1525

jan10 12:10 college

Where, -rwx The file is readable, writable and executable by the owner of the file. Lak

Specifies Owner of the file.

r-x

Indicates the absence of the write permission by the Group owner of the file.

Std

Is the Group Owner of the file.

r--

Indicates read permissions for others.

13. The ‘chmod’ command: The chmod command is used to set the read, write and execute permissions for all categories of users for file. SYNTAX: $ chmod category operation permission file

Umang Jain [A7605217131]

Page 22

Category

Operation

permission

u-users

+ assign

r-read

g-group

-Remove

w-write

o-others

= assign absolutely

x-execute

a-all EXAMPLE: $ chmod u –wx college Removes write & execute permission for users for ‘college’ file. $ chmod u +rw, g+rw college Assigns read & write permission for users and groups for ‘college’ file. $ chmod g=wx college Assigns absolute permission for groups of all read, write and execute permissions for ‘college’ file. 14. The ‘Octal Notations’ command: The file permissions can be changed using octal notations also. The octal notations for file permission are Read permission 4 Write permission

2

Execute permission

1

EXAMPLE: $ chmod 761 college Assigns all permission to the owner, read and write permissions to the group and only executable permission to the others for ‘college’ file. 1.4 GROUPING COMMANDS 1. The ‘semicolon’ command: The semicolon(;) command is used to separate multiple commands at the command line. SYNTAX: $ command1;command2;command3…………….;commandn EXAMPLE: $ who;date 2. The ‘&&’ operator:

Umang Jain [A7605217131]

Page 23

The ‘&&’ operator signifies the logical AND operation in between two or more valid Unix commands. It means that only if the first command is successfully executed, then the next command will executed. SYNTAX: $ command1 && command && command3…………….&&commandn EXAMPLE: $ who && date 3. The ‘||’ operator: The ‘||’ operator signifies the logical OR operation in between two or more valid Unix commands. It means, that only if the first command will happen to be un successfully, it will continue to execute next commands. SYNTAX: $ command1 || command || command3…………….||commandn EXAMPLE: $ who || date 1.5 FILTERS 1. The head filter It displays the first ten lines of a file. SYNTAX: $ head filename EXAMPLE: $ head college $ head -5 college

Display the top ten lines. Display the top five lines.

2. The tail filter It displays ten lines of a file from the end of the file. SYNTAX: $ tail filename EXAMPLE: $ tail college $tail -5 college

Display the last ten lines. Display the last five lines.

3. The pg filter: The pg command shows the file page by page. SYNTAX: $ ls –l | pg 4. The ‘grep’ command: This command is used to search for a particular pattern from a file or from the standard input and display those lines on the standard output. “Grep” stands for “global search for regular expression.”

Umang Jain [A7605217131]

Page 24

SYNTAX: $ grep [pattern] [file_name] EXAMPLE: $ cat > student Arun cse Ram ece Kani cse $ grep “cse” student Arun cse Kani cse 5. The ‘sort’ command: The sort command is used to sort the contents of a file. The sort command reports only to the screen, the actual file remains unchanged. SYNTAX: $ sort filename EXAMPLE: $ sort college OPTIONS: Command

Purpose

Sort –r college

Sorts and displays the file contents in reverse order

Sort –c college

Check if the file is sorted

Sort –n college

Sorts numerically

Sort –m college

Sorts numerically in reverse order

Sort –u college

Remove duplicate records

Sort –l college

Skip the column with +1 (one) option.Sorts according to second column

6. The ‘uniq’ command:

Umang Jain [A7605217131]

Page 25

In any enterprise data processing environment, there is often a duplicate entry creeping in due to faulty data entry. We just saw how sort removes them the –u option. Unix offers a special tool to handle these records SYNTAX: $ uniq filename EXAMPLE: $ cat > student Arun cse Arun cse Ram ece Ram ece Kani cse San cse

$ uniq student Arun cse Ram ece Kani cse San cse 7. The ‘nl’ command: The nl filter adds lines numbers to a file and it displays the file and not provides access to edit but simply displays the contents on the screen. SYNTAX: $ nl filename EXAMPLE: $ nl college 8. The ‘cut’ command: We can select specified fields from a line of text using cut command. SYNTAX: $ cut -c filename

Umang Jain [A7605217131]

Page 26

EXAMPLE: $ cut -c college OPTION: -c – Option cut on the specified character position from each line.

Ex. No:5 The Greatest Among Three Number Date:

Aim To using the shell program to check the greatest among three number. Algorithm Step 1: Start the program Step 2: Read three values to check the greatest. Step 3: Check while if [ $first -gt $sec ] if true else if [ $first -gt $third ] Step 4: Check if if [ $sec -gt $third ] if write the output.

Umang Jain [A7605217131]

Page 27

Step 5: Stop the program.

PROGRAM echo "enter first number" read first echo "enter second number" read sec echo "enter third number" read third if [ $first -gt $sec ] ; then if [ $first -gt $third ] ; then echo -e " $first is greatest number " else echo -e " $third is greatest number " fi else if [ $sec -gt $third ] ; then echo -e " $sec is greatest number " else echo -e " $third is greatest number " fi

Umang Jain [A7605217131]

Page 28

fi OUTPUT

RESULT The program for greatest number among three was compiled and executed successfully.

Ex. No:6 Date:

Even or Odd

Aim To write a program to check if a number is even or odd. Algorithm: Step 1: Start the program Step 2: Read the value to check the even or odd. Step 3: Calculate the rem= rem=$(( $n % 2 )). Step 4: check the remainder if 0 then even or else odd. Step 5: Give the output. Step 6: Stop the program.

Umang Jain [A7605217131]

Page 29

PROGRAM echo -n "Enter number : " read n rem=$(( $n % 2 )) if [ $rem -eq 0 ] then echo "$n is even number" else echo "$n is odd number" fi OUTPUT

Umang Jain [A7605217131]

Page 30

RESULT The even/odd program was compiled and executed successfully.

Ex. No:7 Positive or Negative Date:

Aim To using the shell program to check if a number is positive or negative. Algorithm Step 1: Start the program Step 2: Read a number.

Umang Jain [A7605217131]

Page 31

Step 3: Run if else loop to check whether the number is negative or positive. Step 4: If negative output “Negative” else “Positive”. Step 5: Stop the program.

.

PROGRAM echo "Enter a Number" read num if [ $num -lt 0 ] then echo "Negative" else if [ $num -gt 0 ] then echo "Positive" else echo "Neither Positive Nor Negative" fi fi

Umang Jain [A7605217131]

Page 32

OUTPUT

RESULT The Positie/Negative program was compiled and executed successfully.

Ex. No:8

Arithmetic operations Date:

Aim To using the shell program to perform arithmetic operations. Algorithm Step 1: Start the program

Umang Jain [A7605217131]

Page 33

Step 2: Read two number and a character. Step 3: Use case ch to check character and enter arithmetic operation related to it. Step 4: Check the case and put the output. Step 5: Stop the program.

.

PROGRAM echo "Enter two number" read a read b echo "Menu" echo "1 Add" echo”2 Substract” echo "3 Multiply" echo "4 Divide" echo "5 Exit" echo "Enter your choice" read ch case $ch in

Umang Jain [A7605217131]

Page 34

1) echo `expr $a + $b`;; 2) echo `expr $a - $b`;; 3) echo `expr $a \* $b`;; 4) echo `expr $a / $b`;; 5) exit;; esac

OUTPUT

Umang Jain [A7605217131]

Page 35

RESULT The program for arithmetic operations was compiled and executed successfully.

Ex. No:9

Umang Jain [A7605217131]

Page 36

Sum of even numbers Date:

Aim To using the shell program to find the sum of even numbers. Algorithm Step 1: Start the program Step 2: Read a upper limit number to get sum . Step 3: Initialize the sum and number. Step 4: Use while loop to [ $i -le $n ] and get the output of sum. Step 5: Stop the program.

.

Umang Jain [A7605217131]

Page 37

PROGRAM echo "Enter upper limit" read n i=0 sum=0 while [ $i -le $n ] do sum=`expr $sum + $i` i=`expr $i + 2` done echo "Sum of even number upto $n is : $sum" OUTPUT

RESULT The program to check even numbers was compiled and executed successfully.

Umang Jain [A7605217131]

Page 38

Ex. No:10 Factorial of Given Number Date:

Aim

To write a program to find the factorial of the given number . Algorithm Step 1: Start the program Step 2: Read the value of n Step 3: Initialize i=1,f=1. Step 4: Using formula to find the factorial of the given number Step 5: Print the factorial value Step 6: Stop the program.

Umang Jain [A7605217131]

Page 39

PROGRAM echo "enter the number" read n f=1 i=1 while [ $i -le $n ] do f=`expr $f \* $i` i=`expr $i + 1` done echo "the factorial of $n is $f"

OUTPUT

RESULT The factorial program was compiled and executed successfully.

Umang Jain [A7605217131]

Page 40

Open Ended Lab Sessions

Ex. No:11 Swap Three Number Date:

Aim To using the shell program to swap three number. Algorithm Step 1: Start the program Step 2: Read three number to swap. Step 3: Use a new variable name Temp. Step 4: temp=$first, first=$second, second=$third,third=$temp. Write the output. Step 5: Stop the program.

Umang Jain [A7605217131]

Page 41

PROGRAM echo “Enter first number” read first echo “Enter second number” read second echo “Enter third number” read third temp=$first first=$second second=$third third=$temp echo "After swapping, numbers are:" echo "first = $first, second = $second, third = $third" OUTPUT

RESULT The program to swap three numbers was compiled and executed successfully.

Umang Jain [A7605217131]

Page 42

Ex. No:12 Fibonacci Series Date:

Aim To write a program to perform Fibonacci Series. Algorithm Step 1: Start the program Step 2: Read the input value. Step 3: Find the fibonacci series of given number using the formula Fn=Fn-1 + Fn-2 Step 4: Display the fibonacci series Step 5: Stop the program.

Umang Jain [A7605217131]

Page 43

PROGRAM echo "enter the no " read a i=1 j=1 k=1 echo "Fibonacci series is" echo "$i" while [ $k -le $a ] do p=`expr $i + $j` i=$j j=$p k=`expr $k + 1` echo "$i" done OUTPUT

RESULT The fibonacci program was compiled and executed successfully.

Umang Jain [A7605217131]

Page 44

Ex. No:13 Check whether the Given Number is Palindrome or not Date:

Aim To using the shell program to check the given number is palindrome or not. Algorithm Step 1: Start the program Step 2: Intialize the value rn=0, x=n Step 3: Check while [$n -gt 0] if true do d=`expr $n % 10` Step 4: Check if [$x -eq $rn] if true write number is palindrome. Step 5: Stop the program.

Umang Jain [A7605217131]

Page 45

PROGRAM Echo “Enter the number to check palindrome” Read num s=0 rev=”” temp=$num while [ $num -gt 0 ] do s=$(( $num % 10 )) num=$(( $num / 10 )) rev=$( echo ${rev}${s} ) done if [ $temp -eq $rev ]; then echo "Number is palindrome" else echo "Number is NOT palindrome" fi

Umang Jain [A7605217131]

Page 46

OUTPUT

RESULT The Palindrome program was compiled and executed successfully.

Umang Jain [A7605217131]

Page 47

Related Documents

Os Lab File.docx
April 2020 4
Lab 04 Os Sec A.docx
October 2019 6
Os
November 2019 66
Os
November 2019 58
Os
May 2020 36
Os
November 2019 68

More Documents from ""