Showing posts with label Operating Systems. Show all posts
Showing posts with label Operating Systems. Show all posts

Sunday, March 20, 2011

Revision Operating System - 1

1. What is an Operating System ?

"Operating system is the part of computer system that manages all of the hardware, and all of the software of computer system. It controls every files, every device, every section of main memory, and every nanosecond of processing time."

  • Operating system services
      •  Program Execution
      • I/O Operation
      • File - system Manipulation
      • Communications
      • Error Detection
      • Resource Allocation
      • Accounting
      • Protection

  • Process Concept 
      • A process is an entity that consist of number of elements. Two essential elements of a process are program code (which may be shared with other processes that are executing the same program) and set of data (associated with that code)

Sunday, March 13, 2011

Unix Programs (Operating System Assignment)


UNIX Practicals
 



1. WAS: to display 1 to 10 numbers (while loop)

a=1
while [ $a -le 10 ]
do
echo "$a"
a=`expr $a + 1`
done

2. WAS: to display 1 to 10 numbers (for loop)

for (( a=1;a<=10;a++ ))
do
echo "$a"
done
  
3. WAS: to display 1 to 10 numbers (until loop)

a=1
until [ $a -gt 10 ]
do
echo $a
a=`expr $a + 1`
done




4. WAS: to display 10 to 1 numbers (while loop)

a=10
while [ $a -ge 1 ]
do
echo $a
a=`expr $a - 1`
done  

5. WAS: to display 10 to 1 numbers (for loop)

for (( a=10;a>=1;a-- ))
do
echo "$a"
done

6. WAS: to display 10 to 1 numbers (until loop)

a=10
until [ $a -lt 1 ]
do
echo $a
a=`expr $a - 1`
done   

7. WAS: to display 1 to N numbers (while loop)

echo "Upto what numbers you want"
read n
a=1
while [ $a -le $n ]
do
echo $a
a=`expr $a + 1`
done        




8. WAS: to display 1 to N numbers (for loop)

echo "Upto what numbers you want"
read n
for (( a=1;a<=n;a++ ))
do
echo “$a”
done

9. WAS: to display 1 to N numbers (until loop)

echo "Upto what numbers you want"
read n
a=1
until [ $a -ge $n ]
do
echo $a
a=`expr $a + 1`
done        

10. WAS: to display N to 1 numbers (while loop)

echo "enter the no"
read no
while [ $no -ge 1 ]
do
echo $no
no=`expr $no - 1`
done 

11. WAS: to display N to 1 numbers (for loop)

echo "from what numbers you want"
read n
for (( a=n;a>=1;a-- ))
do
echo “$a”
done




12. WAS: to display N to 1 numbers (Until loop)

echo "enter the no"
read no
until [ $no -le 1 ]
do
echo $no
no=`expr $no - 1`
done 

13. WAS: to find the sum of 1 to 10 numbers (while loop)

$ cat >f4
a=1
sum=0
while [ $a -le 10 ]
do
sum=`expr $sum + $a`
a=`expr $a + 1`
done
echo "total is $sum"

14. WAS: to find the sum of 1 to 10 numbers (for loop)

a=1
sum=0
for (( a=1;a<=10;a++ ))
do
sum=`expr $sum + $a`
done
echo "total is $sum"

15. WAS: to find the sum of 1 to 10 numbers (until loop)

a=1
sum=0
until [ $a -ge 10 ]
do
sum=`expr $sum + $a`
a=`expr $a + 1`
done
echo "total is $sum"
16. WAS: to find the factorial of a given no (while loop)

fact=1
echo "enter the no"
read no
while [ $no -gt 0 ]
do
fact=`expr $fact \* $no`
no=`expr $no - 1`
done
echo "factorial is $fact" 

17. WAS: to find the factorial of a given no (for loop)

fact=1
echo "enter the no"
read no
for (( no=no;no>0;no-- ))
do
fact=`expr $fact \* $no`
done
echo "factorial is $fact" 

18. WAS: to find the factorial of a given no (until loop)

fact=1
echo "enter the no"
read no
until [ $no -lt 0 ]
do
fact=`expr $fact \* $no`
no=`expr $no - 1`
done
echo "factorial is $fact" 

19. WAS: to display Fibonacci series (while loop)

a=0
b=1
echo " how much steps you want "
read no
echo $a
echo $b
x=`expr $no - 2`
while [ $x -gt 0 ]
do
c=`expr $a + $b`
echo $c
a=$b
b=$c
x=`expr $x - 1`
done     

20. WAS: to display Fibonacci series (for loop)

a=0
b=1
echo " how much steps you want "
read no
echo $a
echo $b
x=`expr $no - 2`
for (( ;x>0;x-- ))
do
c=`expr $a + $b`
echo $c
a=$b
b=$c
done



21. WAS: to display Fibonacci series (Until loop)

a=0
b=1
echo " how much steps you want "
read no
echo $a
echo $b
x=`expr $no - 2`
until [ $x -lt 0 ]
do
c=`expr $a + $b`
echo $c
a=$b
b=$c
x=`expr $x - 1`
done         

22. WAS: to get the reverse number of given digit (while loop)

echo "enter the number"
read no
while [ $no -gt 0 ]
do
x=`expr $no % 10`
echo $x
no=`expr $no / 10`
done

23. WAS: to get the reverse number of given digit (for loop)

echo "enter the number"
read no
for (( no=no;no>0;no=no/10 ))
do
x=`expr $no % 10`
echo $x
done

24. WAS: to get the reverse number of given digit (Until loop)

echo "enter the number"
read no
until [ $no -lt 0 ]
do
x=`expr $no % 10`
echo $x
no=`expr $no / 10`
done

25. WAS: to display the multiplication table of a particular number (while loop)

i=1
echo "enter the number for multiplication table"
read no
while [ $i -le 10 ]
do
x=`expr $i \* $no`
echo "$i x $no = $x"
i=`expr $i + 1`
done

26. WAS: to display the multiplication table of a particular number (for loop)

echo "enter the number for multiplication table"
read no
for (( i=1;i<=10;i++ ))
do
x=`expr $i \* $no`
echo "$i x $no = $x"
done

27. WAS: to display the multiplication table of a particular number (until loop)

i=1
echo "enter the number for multiplication table"
read no
until [ $i -ge 10 ]
do
x=`expr $i \* $no`
echo "$i x $no = $x"
i=`expr $i + 1`
done

28. WAS: to display the multiplication table from upto N number (While loop)

i=1
j=1
echo "enter upto wht number you want the tables"
read num
while [ $j -le $num ]
do
while [ $i -le 10 ]
do
x=`expr $i \* $j`
echo " $i x $j = $x"
i=`expr $i + 1`
done
j=`expr $j + 1`
done         

29. WAS: to display the multiplication table from upto N number (While loop)

echo "enter upto wht number u wnt"
read no
for (( j=1;j<=no;j++ ))
do
for (( i=1;i<=10;i++ ))
do
t=`expr $i \* $j`
echo "$i x $j = $t"
done
done  

30. WAS: to display the multiplication table from upto N number (Until loop)

i=1
j=1
echo "enter upto wht number ypu want the tables"
read num
until [ $j -ge $num ]
do
until [$i -ge 10 ]
do
x=`expr $i \* $j`
echo " $i x $j = $x"
i=`expr $i + 1`
done
j=`expr $j + 1`
done         

31. WAS: to do sum of any digit (while loop)

echo "enter any no"
read no
sum=0
while [ $no -gt 0 ]
do
x=`expr $no % 10`
sum=`expr $sum + $x`
no=`expr $no / 10`
done
echo "sum = $sum"

32. WAS: to do sum of any digit (for loop)

echo "enter any no"
read no
sum=0
for (( no=no;no>0;no/=10 ))
do
x=`expr $no % 10`
sum=`expr $sum + $x`
done
echo "sum = $sum"

33. WAS: to do sum of any digit (Until loop)

echo "enter any no"
read no
sum=0
until [ $no -lt 0 ]
do
x=`expr $no % 10`
sum=`expr $sum + $x`
no=`expr $no / 10`
done
echo "sum = $sum"
34. Write a shell script to find even or not.
echo "enter the no"
read no
x=`expr $no % 2`
if [  $x -eq 0 ]
then
echo "even"
else
echo "odd"
fi

35. WAS. To find the given year is leap year or not

echo "enter the year"
read year
x=`expr $year % 4`
if [ $x -eq 0 ]
then
echo "leap year"
else
echo "not leap year"
fi

36. WAS: to find the greatest of all from 3 numbers.

echo "enter three numbers"
read n1
read n2
read n3
if [ $n1 -gt $n2 ] && [ $n1 -gt $n3 ]
then
echo "$n1 is greater"
elif [ $n2 -gt $n3 ] && [ $n2 -gt $n1 ]
then
echo "$n2 is greater"
else
echo "$n3 is greater"
fi
36. WAS: to find the greatest of all from 3 numbers.

i=1
max=$1
for i in $*
do
if [ $i -gt $max ]
then
max=$i
fi
done
echo "max = $max"

37. WAS: to find percentage and class of a student.

echo "enter 5 sub marks"
read s1
read s2
read s3
read s4
read s5
tot=`expr $s1 + $s2 + $s3 + $s4 + $s5`
per=`expr $tot \* 100 / 5`
if [ $per -gt 70 ]
then
echo "distinction"
elif [ $per -gt 60 ]
then
echo "first class"
elif [ $per -gt 50 ]
then
echo "second class"
else
echo "third class"
fi



38. WAS: to find it is prime or not

x=0
i=2
echo "enter the no"
read no
while [ $i -lt $no ]
do
y=`expr $no % $i`
if [ $y -eq 0 ]
then
x=1
fi
i=`expr $i + 1`
done
if [ $x -eq 0 ]
then
echo "prime"
else
echo "not prime"
fi       

39. WAS: to find string is equal or not

if test "$1" == "$2"
then
echo "equal"
else
echo "not equal"
fi   

40. WAS: to find check that file exist or not

if test -a f1
then
echo "exist"
else
echo "dosent exist"
fi    
41. WAS: to find that file is readable or not

if test -r f1
then
echo "readable"
else
echo "not readable"
fi  

42. WAS: to find that file is writable or not

if test -w f1
then
echo "writeable"
else
echo "not writeable"
fi  

43. WAS: to find that string is null or not

if test -z $1
then
echo "NULL"
else
echo "NOT NULL"
fi  

44. WAS: to find that file is executable or not

if test -x f1
then
echo "executable"
else
echo "not"
fi   



45. WAS: to find the minimum and maximum from given 5 numbers

i=1
min=$1
max=$1
for i in $*
do
if [ $i -lt $min ]
then
min=$i
fi
if [ $i -gt $max ]
then
max=$i
fi
done
echo "min = $min and max = $max"

46. WAS: to count how many even and odd numbers are there.

i=1
a=0
b=0
for i in $*
do
j=`expr $i % 2`
if [ $j -eq 0 ]
then
a=`expr $a + 1`
fi
if [ $j -eq 1 ]
then
b=`expr $b + 1`
fi
done
echo "even = $a and odd = $b"

Monday, January 17, 2011

Different Desktop Environments on Linux

Different Desktop Environments on Linux

All computers are nothing without Operating Systems, much the same as the principle that power is nothing without control. Lamborghini could make the fastest car in the world next year, nothing coming even relatively close to it. However if they weld the doors closed and fill the whole cabin with cement, so there is no way to ever drive or operate the car, the whole entire thing is worthless. Think of this as a computer without an operating system, it’s a wild beast, waiting to be tamed. When you choose an OS not only are you establishing a whole “front-end” from which you can operate the computer, your pouring a little bit of yourself in it as well. Changing the color of the car, from my earlier metaphor if you will.
There are a TON of things that happen when you install an OS, but you only see the graphical parts of it, the “graphical user interface” or GUI. Obviously, if that's the main thing your seeing, its fairly important to you on every level. Linux however, took this whole concept a step further, and established several “flavors” of GUI for your desktop on your Linux OS. Wikipedia describes a desktop environment as just that: A Desktop Environment (DE) commonly refers to a style of graphical user interface (GUI) derived from the desktop metaphor that is seen on most modern personal computers.
This is very important, because if you’ve ever used Linux AT ALL, you know that choice is everything. It’s not about just using “what works” or “whats provided”, its about carving your own path based on precisely what YOU want. If you don’t like the way the taskbar functions on one particular distribution or “distro” of Linux, and you think that the support is poor and you could never see yourself using it, just choose a different one! It’s about having absolutely everything as close to tailor-made to your specific liking as you can, hence why desktop environments are so important.
It’s the GUI, it’s what you will be looking at and toying with directly for hours and hours and hours, lets spend some time finding out what you want, and let’s do it right. The problem being that I really can’t just choose one for you, it’s not that easy. It’s purely aesthetics, it really is, however things like that do in fact matter when your spending that much time dealing with it. Listed below is a number of screenshots of different DE’s, or desktop environments, notice that the differences are minimal, but there is certainly is still a difference between each of them.
Gnome, KDE, XFCE, and LXDE are just a few of Linux distro’s most popular DE’s, mostly just because they are the main ones. There is a direct correlation between the name of the DE and the distro of Linux that your using. If you look up things regarding Ubuntu, you will notice that it comes standard with the GNOME DE. However, if you look at Xubuntu, a different branch or “flavor” of Ubuntu, you might wonder what the difference between the two is. Sure enough, the X stands for the XFCE type DE that Xubuntu uses, meaning that you can deduce that Xubuntu is the same as Ubuntu, except with an XFCE DE, without even researching if you’d seriously want to try the distro or not you already know what DE it uses.

Difference between Internal And External Command in Linux.


Internal commands are the commands that are executed 
directly by the shell. These commands will not have a 
separate process running for each.
External commands are the commands that are executed by the 
kernal. These commands will have a process id running for 
it.
Internal Commands: Echo, CD
External Commands: cat, ls

Friday, December 24, 2010

Preemptable and Nonpreemptable Resource - OS

Resources

Deadlocks can occur when processes have been granted exclusive access to devices, files and so forth. To make the discussion of deadlocks as general as possible, we will refer to the objects granted as resources. A resources can be a hardware device (e.g. , a tape drive) or a piece of information (e.g., a locked record in the database). A computer will normally have many different resources that can be acquire. A resourece is anything that can be used by only a single process at any instant of time.  

·         Preemptable and  Nonpreemptable Resource 


Resources come in two types: Preemptable and Nonpreemptable. A Preemptable resource is one that can be taken away from the process owning it with no ill effects.  


Memory is an example of a Preemptable resource. Consider, for example, a system with 32 MB of user memory, one printer, and two 32-MB processes that each want to print something. Process A request and gets the printer, then start to compute the values to print. Before it has finished with the computation, it exceeds its time quantum and is swapped out.


            Process B now runs and tires, unsuccessfully, to acquire the printer. Potentially, we now have a deadlock situation, because A has the printer and B has the memory, and neither can proceed without the resource held by the other. Fortunately, it is possible to preempt (take away) the memory from B by swapping it out and swapping A in.  Now A can run, do its printing, and then release the printer. No deadlock occurs.


A Nonpreemptable resource, in contrast is one that cannot be taken away from its current owner without causing the computation to fail. If a process has begun to burn a CD-ROM, suddenly taking the CD recorder away from it and giving it to another process will result in a garbled CD. CD recorders are not Preemptable at an arbitrary moment.  

Wednesday, December 22, 2010

Deadlocks - (Operating System)

DEADLOCKS

            Computer systems are full of resources that can only be used by one process at a time. Common examples include printer, tape drives, and slots in the system’s internal tables. Having two processes simultaneously writing to the printer leads to gibberish. Having two processes using the same file system table slot will invariably lead to a corrupted file system.


For many applications, a process needs exclusive access to not one resource, but several. Suppose, for example, two processes each want to record a scanned document on a CD. Process A requests permission to use the scanner and is granted it.  Process B is programmed differently and the request CD recorder first and is also granted it. Now A asks the CD recorder, but request is denied until B releases it. Unfortunately, instead of releasing for CD recorder B asks for the scanner. At this point both processes are blocked and will remain so forever. This situation called a deadlock.

 
            Deadlock can also occur across machines. For example, many offices have local area network with many computer connected to it. Often devices such as scanner, CD recorders, printer and tape drives are connected to the network as shared resources, available to any user on the machine. If these devices can be reserve remotely, the same kind of deadlocks can occur as described above. More complicated situation can cause deadlock involving three, four or more devices and users.

Monday, December 20, 2010

Process Scheduling Algorithms


The process Scheduler relies on a process scheduling algorithm, based on a specific policy, to allocate the CPU and move jobs through the system. Early operating system non preemptive policies designed to move batch jobs through the system as efficiency as possible. Most current system, with their emphasis on interactive use and response time, use an algorithm that takes care of the immediate requests of interactive users. CPU scheduling deals with this problem of deciding which of the processes in the ready queue is to be allocated the CPU.


Preemptive scheduling is more useful in high priority process which requires immediate response. For example in Real Time Operating System the consequences of missing one interrupt could be dangerous. 


First Come First Served Scheduling (FCFS)

It is simplest CPU scheduling algorithm. With this scheme, the process that requests the CPU first is allocated the CPU first. The implementation of FCFS policy is easily managed with a FIFO queue. When a process enters in a ready queue, its PCB is linked onto the tail of the queue. When the CPU is free, it is allocated to the process at the head of the queue. The running process is then removed from the queue. The code for the FCFS scheduling is simple to write and understand.

In a strictly FCFS system there are no WAIT queues (each job is run to completion), although there may be systems in which control (context) is switched on a natural wait (I/O request) and then the job resumes on I/O completion.


Process                       Burst Time
P1                                           12
P2                                           6
P3                                           7



P1
P2
P3
       0                                                               12                                    18                                                            25


The waiting time is 0 millisecond for process P1, 12 milliseconds for process P2, and 18 milliseconds for process P3. Thus the average waiting time is (0 + 12 + 18)/3 = 10 milliseconds.


Avg. Waiting Time = 0 + 12 + 18 / 3 = 10 milliseconds


Sunday, December 19, 2010

SCHEDULING CRITERIA

·         CPU Utilization

We want to keep the CPU as busy as possible. CPU utilization may range from 0 to 100 percent. In a real time operating system, it should range from 40 percent (for a lightly loaded system) to 90 percent (for a heavily used system). Maximum utilization of CPU can be done if all processes are CPU bound. Round Robin is best example for CPU utilization.

·         Throughput

If the CPU is busy in executing processes, then work is being done. Throughput is the amount of work that the system is able to do per unit time. It is measured as the number of processes that are complicated by the system per unit time. For example, n processes are complicated in an interval of t second; the throughput is taken as n/t processes per second during that interval. Throughput is normally measured in processes/hour. Note that value of throughput does not depend only on the capabilities of a system, but also nature of jobs being processes by the system. For long processes, throughput may be one process/hour; and for short processes, throughput may be 100 processes/hour. There must be maximum number of processes in a short time.      

·         Turnaround Time

From the point of view of a particular process, the important criterion is how long it takes to execute that processes. The interval from the time of submission of a process to the time of completion is the turnaround time. Turnaround time is the sum of the Periods spent waiting to get into memory, waiting in the ready queue, executing on the CPU, and doing I/O. Turnaround time must be less.

·         Waiting Time

The CPU scheduling algorithm does not affect the amount of time during which a process executes or does I/O; it affects only the amount of time that a process spends waiting in the ready queue. Waiting time is the sum of the period spent waiting in the ready queue.

·         Response Time

In the interactive system, turnaround time may not be the criterion. Often, a process can produce some output fairly early and can computing new results while previous results are being output to the users. Thus, another measure is the time from submission of a request until the first response is produced.  This measure, called response time.