Professional Documents
Culture Documents
VISION
MISSION
DEPARTMENT
VISION
MISSION
To prepare the students for a prospective career in IT industry and for higher learning by
imparting sound technical knowledge.
To carry out research in cutting edge technologies in computer engineering to meet the
requirement of the industry and society.
COMMANDS:
cat --- for creating and displaying short files
chmod --- change permissions
cd --- change directory
cp --- for copying files
date --- display date
echo --- echo argument
ftp --- connect to a remote machine to download or upload files
grep --- search file
head --- display first part of file
ls --- see what files you have
lpr --- standard print command
more --- use to read files
mkdir --- create directory
mv --- for moving and renaming files
ncftp --- especially good for downloading files via anonymous ftp.
print --- custom print command
pwd --- find out what directory you are in
rm --- remove a file
rmdir --- remove directory
rsh --- remote shell
setenv --- set an environment variable
sort --- sort file
tail --- display last part of file
tar --- create an archive, add or extract files
telnet --- log in to another machine
wc --- count characters, words, lines
1. To create a file.
3
Syntax: $ cat>filename
Example: $ cat>ex1
8. To delete a file
Syntax: $ rm filename
Example: $ rm ex1
13. Echo
i. To display the filename starting with single letter
Syntax: $ echo?
15. Head
i. To display first 10 lines
Syntax: $ head filename
19. Sort
i. To reverse and sort the content of file
Syntax: $ sort –r filename
Example: $ sort –r ex1
AIM:
To work with some of the general purpose utility commands in UNIX.
6
COMMANDS:
1. Calendar:
i. To display the calendar.
Syntax: $ cal
2. Date:
i. To display system date.
Syntax: $ date
Output: Tue Jan 20 10:54:25 IST 2009
3. WHO
i. To display the login details
7
Syntax: $ who
Output: root :0 Jan 20 10:51
cs1010 pts/0 Jan 20 10:51 (172.16.1.72)
4. MAN
i. It is used to view more details of all the commands
Syntax: $ man command_name
Example: $ man date
SHELL PROGRAMMING
AIM:
8
To find the sum and average of N numbers using shell programming.
ALGORITHM:
SAMPLE OUTPUT:
AIM:
To find the largest and smallest of three numbers using shell programming.
9
ALGORITHM:
SAMPLE OUTPUT:
AIM:
To find the given year is a leap year or not using shell programming.
ALGORITHM:
OUTPUT:
[meera@localhost meera]$ sh leap.sh
Leap Year or Not
Enter the Year
1920
1920 is a leap year
[meera@localhost meera]$ sh leap.sh
Leap Year or Not
Enter the Year
1991
1991 is not a leap year
AIM:
To find whether the given number is odd or even using shell programming.
ALGORITHM:
SAMPLE OUTPUT:
AIM:
To write a program to identify whether the given number is positive or negative using shell
programming.
ALGORITHM:
11
Step 1: Read the input
Get the value of n
Step 2: If n is greater than 0
then print n is a positive number.
Step 3: Else if n is less than 0
then print n is a negative number.
Step 4: Else print n is equal to zero.
SAMPLE OUTPUT:
AIM:
To calculate the sum of digits using shell programming.
ALGORITHM:
OUTPUT:
12
Ex. No. 2g Fibonacci Series
AIM:
To write a shell program to find the Fibonacci series.
ALGORITHM:
OUTPUT:
ALGORITHM:
SAMPLE OUTPUT:
AIM:
To calculate the mark list of a student using shell programming.
ALGORITHM:
OUTPUT:
OUTPUT:
[meera@localhost meera]$ sh sumofseries.sh
Sum of Series
Enter the Number:
5
Sum= 55
AIM:
To write a program to find the sequence of odd numbers present up to given n number.
ALGORITHM:
OUTPUT:
AIM:
To write a shell program to find whether the number is prime or composite.
ALGORITHM:
OUTPUT:
16
[meera@localhost meera]$ sh primecomposite.sh
Prime or composite
Enter the value of n:
6
6 is composite
[meera@localhost meera]$ sh primecomposite.sh
Prime or composite
Enter the value of n:
3
3 is prime
AIM:
To write a shell program to perform the arithmetic operation using switch case.
ALGORITHM:
OUTPUT:
Enter ur choice
1----Addition
17
2----Subtraction
3----Multiplication
4----Division
5----Modulo
1
Enter ur number
56
23
The sum of 56 and 23 is 79
AIM:
To write a shell program to find the length of the string.
ALGORITHM:
OUTPUT:
AIM:
To write a shell program to perform various pattern search using file.
ALGORITHM:
AIM:
To write a shell program to perform sum of series using switch case.
ALGORITHM:
OUTPUT:
20
Ex. No. 2q Palindrome – Reversing a Number
AIM:
To write a shell program to find the palindrome of a given number.
ALGORITHM:
AIM:
To write a program to check whether a login is connected or not.
ALGORITHM:
21
OUTPUT:
SYSTEM CALLS
AIM:
To write a program to create a child process using the system calls –fork.
ALGORITHM:
OUTPUT:
Parent is 10968
HELLO FROM CHILD PROCESS
CHILD ID is 10968
Parent is 10967
HELLO FROM PARENT PROCESS 10967
HELLO FROM CHILD PROCESS 10968
AIM:
To write a program to display time and date using exec system call.
ALGORITHM:
OUTPUT:
23
[meera@localhost meera]$ cc -o exec.out exec.c
[meera@localhost meera]$ ./exec.out
Child Id is 10983
Parent Id is 10982
Tue Jan 27 11:17:10 IST 2009
End of file
AIM:
To write a program to implement STAT system call.
ALGORITHM:
Step 1: Include the necessary header file.
Step 2: Check the status of the given file.
Step 3: Store the status as integer value in the variable flag.
Step 4: If the argc is not equal to 2 then print filename is not given.
Step 5: Else if flag is equal to -1 then print file does not exist.
Step 6: Else print the file link, devices, inodes, protection, size, ownership, block size and time.
OUTPUT:
AIM:
To write a program using wait system call.
24
ALGORITHM:
Step 1: Create child process using fork system call.
Step 2: Display the child id and status of the child process.
Step 3: Using exec() system call display the time and date.
Step 4: Return the child ID as the waiting ID using wait() system call.
cid=wait(&status)
Step 5: Display waiting ID and status
OUTPUT:
[meera@localhost meera]$ cc -o wait.out wait.c
[meera@localhost meera]$ ./wait.out
Parent Id is 11004
Status Id is 134513794
Tue Jan 27 11:27:27 IST 2009
Id is 11004 Status is 0
AIM:
To write a program to implement the concept of I/O call.
ALGORITHM:
25
Step 2: Declare the variables needed.
Step 3: check if argc!=2 then
print “File name is not given”
Step 4: Open the file specified in the command prompt.
fd=open(argv[1],0)
Step 5: Check if fd!=-1 then write the value of n into the file.
Step 6: Else print no such file exist and perform the following process.
Step 6a: Create a new file by entering the choice Y.
Step 6b: Create the file using the built in function “ch mode+rw”
Step 6c: Concatenate the arguments and the attributes using strcat.
Step 6d: Get the value of n one by one and store the value n into the new file using write ().
OUTPUT:
26
4. Define open() system call
5. Define close() system call
6. What is the use of fork() system call?
AIM:
To write a program for the simulation of copy command.
ALGORITHM:
OUTPUT:
AIM:
To write a program to implement the simulation of move command.
ALGORITHM:
OUTPUT:
28
Moving a file
move[.src][.dest]
[meera@localhost meera]$ ./move.out filename2 file2
AIM:
To write a program for the simulation of CAT command.
ALGORITHM:
OUTPUT:
30
Ex. No. 5d Simulation of GREP Command
AIM:
To write a program to implement the simulation of grep command.
ALGORITHM:
OUTPUT:
AIM:
To write a program for simulation of LS command.
ALGORITHM:
OUTPUT:
Total files: 71
33
First Come First Serve Scheduling
AIM:
To write a program using C in Unix environment to implement the first come first serve
scheduling.
ALGORITHM:
Step 1: Include the header files and declare the array size and variable.
Step 2: Get the total number of jobs in array by using for loop.
Step 3: Get the waiting time and turn around time.
Step 4: Print the values of waiting time and turn around time.
Step 5: Compute the average waiting time and turn around time and print their values.
EXAMPLE:
Suppose there are 3 processes in the ready list. Further assume that they had entered into the
ready list in the order P0, P1, P2.
i T(Pi)
0 24
1 3
2 3
Waiting Time:-
W(P0)=0
W(P1)= TRND(P0)=24 or W(P1)= W(P0)+burst time of P0 = 0+24=24
W(P2)= TRND(P1)=27
OUTPUT:
P0 24 0 24
P1 3 24 27
P2 3 27 30
35
Ex. No. 6b Shortest Job First Scheduling
AIM:
To write a program using C in UNIX environment to implement the shortest job next concept.
ALGORITHM:
EXAMPLE:
In the following example assume no other jobs arrive during the servicing of all jobs in the ready
list. Assume there are 4 jobs.
i T(Pi)
0 5
1 10
2 8
3 3
Since the service time of P3 is 3, which is the shortest, P3 is scheduled first and then P0 is
scheduled next and so on.
Gantt Chart:-
0 3 8 16 26
P3 P0 P2 P1
Waiting Time:-
W(P0)=3
W(P1)=16
W(P2)= 8
W(P3)= 0
OUTPUT:
P0 3 0 3
P1 5 3 8
P2 8 8 16
P3 10 16 26
37
Ex. No. 6c Round Robin Scheduling
AIM:
To write a program using C in UNIX environment to implement Round-robin scheduling
concept.
ALGORITHM:
EXAMPLE:
Suppose the ready list contains the processes as shown in table and time quantum is 4 with a
negligible amount of time for context switching.
i T(Pi)
0 24
1 3
2 3
Gantt Chart:-
0 4 7 10 14 18 22 26 30
P0 P1 P2 P0 P0 P0 P0 P0
Waiting Time:-
38
W(P0)=26-(3+3+4+4+4+4) = 26-20 =6
W(P1)=4
W(P2)=7
OUTPUT:
ROUND ROBIN SCHEDULING ALGORITHM
AIM:
39
To implement the priority scheduling using C in UNIX environment.
ALGORITHM:
EXAMPLE:
Suppose the ready list contains the processes as shown in table.
i T(Pi) Priority
0 24 2
1 3 1
2 3 3
Gantt Chart:-
0 3 27 30
P1 P0 P2
Waiting Time:-
W(P0)=3
W(P1)=0
W(P2)=27
AIM:
41
To write a program to implement producer consumer problem concept.
ALGORITHM:
OUTPUT:
Choices are
1. Producer Routine
2. Consumer Routine
3. Display the contents of the buffer
4. Exit
Enter your choice: 1
Choices are
1. Producer Routine
2. Consumer Routine
3. Display the contents of the buffer
4. Exit
Enter your choice: 2
42
Item p1 is successfully consumed
Choices are
1. Producer Routine
2. Consumer Routine
3. Display the contents of the buffer
4. Exit
Enter your choice: 1
Choices are
1. Producer Routine
2. Consumer Routine
3. Display the contents of the buffer
4. Exit
Enter your choice: 3
p2
p3
Choices are
1. Producer Routine
2. Consumer Routine
3. Display the contents of the buffer
4. Exit
Enter your choice: 4
Sample Viva-Voce questions:
1. What is a semaphore?
2. What kind of operations is possible on a semaphore?
3. What is a critical section?
4. When does the deadlock occurs?
5. Define IPC?
6. Tell us something about mutex.
7. What is a Safe State and what is its use in deadlock avoidance?
AIM:
To write a C program to implement the memory management scheme using best fit.
ALGORITHM:
OUTPUT:
AIM:
To write a C program to implement the memory management scheme using first fit
ALGORITHM:
OUTPUT:
AIM:
To write a C program to implement the memory management scheme using worst fit.
ALGORITHM:
OUTPUT:
46
The process 0 [size 145] allocated to block 600
AIM:
To write a ‘C’ program to implement the Disk Scheduling algorithm for First Come First Served
(FCFS), Shortest Seek Time First (SSTF), and SCAN.
PROBLEM DESCRIPTION:
47
Disk Scheduling is the process of deciding which of the cylinder request is in the ready queue is
to be accessed next.
The access time and the bandwidth can be improved by scheduling the servicing of disk I/O
requests in good order.
Access Time:
The access time has two major components: Seek time and Rotational Latency.
Seek Time:
Seek time is the time for disk arm to move the heads to the cylinder containing the desired
sector.
Rotational Latency:
Rotational latency is the additional time waiting for the disk to rotate the desired sector to the
disk head.
Bandwidth:
The disk bandwidth is the total number of bytes transferred, divided by the total time between
the first request for service and the completion of the last transfer.
ALGORITHM:
1. Input the maximum number of cylinders and work queue and its head starting position.
2. First Come First Serve Scheduling (FCFS) algorithm – The operations are performed in order
requested
3. There is no reordering of work queue.
4. Every request is serviced, so there is no starvation
5. The seek time is calculated.
6. Shortest Seek Time First Scheduling (SSTF) algorithm – This algorithm selects the request
with the minimum seek time from the current head position.
7. Since seek time increases with the number of cylinders traversed by the head, SSTF chooses the
pending request closest to the current head position.
8. The seek time is calculated.
9. SCAN Scheduling algorithm –The disk arm starts at one end of the disk, and moves toward the
other end, servicing requests as it reaches each cylinder, until it gets to the other end of the disk.
10. At the other end, the direction of head movement is reversed and servicing continues.
11. The head continuously scans back and forth across the disk.
48
12. The seek time is calculated.
13. Display the seek time and terminate the program.
Output
1. FCFS
2. SSTF
3. SCAN
4. EXIT
FCFS
*****
MENU
1. FCFS
2. SSTF
3. SCAN
4. EXIT
49
Enter your choice: 2
SSTF
*****
MENU
1. FCFS
2. SSTF
3. SCAN
4. EXIT
SCAN
*****
MENU
1. FCFS
2. SSTF
3. SCAN
4. EXIT
50
Experiments addressing COs:
AIM:
PROBLEM DESCRIPTION:
Page replacement algorithms are used to decide what pages to page out when a page needs to be
allocated. This happens when a page fault occurs and free page cannot be used to satisfy allocation
LRU:
“Replace the page that had not been used for a longer sequence of time”. The frames are empty in
the beginning and initially no page fault occurs so it is set to zero. When a page fault occurs the page
reference sting is brought into the memory. The operating system keeps track of all pages in the
memory, thereby keeping track of the page that had not been used for longer sequence of time. If the
page in the page reference string is not in memory, the page fault is incremented and the page that had
not been used for a longer sequence of time is replaced. If the page in the page reference string is in the
memory take the next page without calculating the next page. Take the next page in the page reference
string and check if the page is already present in the memory or not. Repeat the process until all pages
are referred and calculate the page fault for all those pages in the page references string for the number
of available frames.
Algorithm
OUTPUT
[anandh@localhost ~]$ ./a.out
52