Question
1 Write an algorithm/program that accepts an input a decimal
number and converts it into binary representation.
#include <conio.h>
int c,r,f,i[16],j,rw,cl;
void main(void)
{
int num,a;
char ch;
void bin(int);
clrscr();
printf("\n\n\t\tEnter a number = ");
scanf("%d",&num);
fflush(stdin);
bin(num);
}
//binary conversion function
void bin(int no)
{
c=no/2;
r=no%2;
i[j--]=r;
if(c<2)
{
i[j--]=c;
printf("\n\n\t\t\t Ans = ");
for(f=0;f<=15;f++)
{
printf("%d",i[f]);
if(rw==cl)
{ printf(" ");
cl=cl+4;
}
rw++;
}
}
else
bin(c);
}
Question 2 Consider the following
set of processes that arrive in the ready queue at the
same time:
Process CPU
JOB1 6
JOB2 8
JOB3 7
JOB4 1
JOB5 5
Consider the following scheduling algorithms:
First Come First Serve (FCFS), SJF (shortest job first)
and Round Robin (quantum = 1)
What is the turnaround time of each process for each of
the above scheduling algorithms?
What is the waiting time of each process for each of the
above scheduling algorithms?
First we define Turnaount time, waiting time is given
below :-
Turnaround Time: Actually, turnaround time is the total
lifetime of a process. It is the time from the startup
of the process to its end. Turnaround time includes the
time spent while loading the process into the memory and
the time while waiting in the ready queue or for the I/O
to be completed.
Waiting Time :Waiting time is the all that time in
which the process was waiting to get the CPU for its
processing. In single process system a process might
wait for CPU while it is performing I/O or any system
specific job but in a multiprocessing system it must
also wait until other processes have taken their time.
Now, let us one by one understand each specified scheduling
algorithm and calculate the corresponding turnaround
time and waiting time with the help of the given ready
queue of five jobs.
FCFS:-
JOB1 JOB2 JOB3 JOB4 JOB5
Start Time (Waiting Time) 0 6 14 21 22
CPU Time 6 8 7 1 5
End Time (Turnaround Time)
(Start Time + CPU Time) 6 14 21 22 27
Average Waiting Time (0 + 6 + 14 + 21 + 22) / 5 = 63
/ 5 = 12.60
Average Turnaround Time (6 + 14 + 21 + 22 + 27) / 5
= 90 / 5 = 18.00
SJF:-
JOB4 JOB5 JOB1 JOB2 JOB3
Start Time (Waiting Time) 0 1 6 12 17
CPU Time 1 5 6 7 8
End Time (Turnaround Time)
(Start Time + CPU Time) 1 6 12 19 25
Average Waiting Time (0 + 1 + 6 + 12 + 17) / 5 = 63
/ 5 = 7.5
Average Turnaround Time (1 + 6 + 12 + 19 + 25) / 5 =
90 / 5 = 12.50
Round Robin:Round Robin algorithm takes control from
the process after a fixed interval and gives it to the
another one.
J1 J2 J3 J4 J5 J1 J2 J3 J5 J1 J2 J3 J5 J1 J2 J3 J5
Quantum Number 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
17
CPU Time Used 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
CPU Time Left 5 7 6 0 4 4 6 5 3 3 5 4 2 2 4 3 1
J1 J2 J3 J5 J1 J2 J3 J2 J3 J2
Quantum Number 18 19 20 21 22 23 24 25 26 27
CPU Time Used 1 1 1 1 1 1 1 1 1 1
CPU Time Left 1 3 2 0 0 2 1 1 0 0
JOB1 JOB2 JOB3 JOB4 JOB5
Turnaround Time 22 27 26 4 21
CPU Time 6 8 7 1 5
Waiting Time 16 19 19 3 16
Average Waiting Time (16 + 19 + 19 + 3 + 16) / 5 = 73
/ 5 = 14.60
Average Turnaround Time (22 + 27 + 26 + 4 + 21) / 5
= 100 / 5 = 20.00
Question 3 Compare and
contrast the features of UNIX and LINUX operating systems.
Linux has a larger availability of software and drivers
then most versions of UNIX. Variants of UNIX such as
SUN Solaris may have about the same or more availability
of software and drivers then some versions of Linux.
Linux issues and bugs generally are always fixed extremely
fast and will likely be fixed before an issue in UNIX
is fixed.
Linux is available for free or for a small cost. Most
versions of UNIX or Variants of UNIX can be very expensive.
It is important to note that versions of SUN Solaris
are available for free for end-users.
Many versions of UNIX are a project of a centralized
company and all issues, information and support are
maintained at one central location.
Many versions of UNIX allow for very large scalability
and maintain reliability.
Multi-user, multi-tasking -- UNIX and LINUX has always
been capable of running multiple programs at one time
and supporting multiple users simultaneously. This means
that file, print and remote access servers can be implemented
using any UNIX-based system.
Question 4 Write the UNIX
commands for the following:
(a) Use the more command, and a pipe to send the contents
of your .profile and .shrc files to the screen.
(b) How could you use head and tail in a pipeline to
display lines 25 through 75 of a file?
(c) To search the /etc/passwd file for the lines containing
any input string given by the user.
(d) To see the lines in /etc/passwd that begins with
the character "a".
(e) List all the files in the /tmp directory owned
by the user root.
(f) To see a complete listing of all the processes
currently scheduled.
(g) Use the ps command, and the grep command, in a
pipeline to find all the processes owned by you.
(h) To force termination of a job whose process ID
is given.
(i) Sort the /etc/passwd file, place the results in
a file called foo, and trap any errors in a file called
err with the command.
(j) To sort a file called foo, and place the results
in a file called bar.
(a)More : Display output one screen at a time
cat .profile .shrc | more
(b) cat file | head -75 | tail -50
(c) grep -r 'hello' /etc/passwd
(d) grep -C 1 'a\<' /etc/passwd
(e) ls -l /tmp | grep 'root'
(f) ps command is used for displaying list of currently
running processes.
(g) ps -ef | grep yourusername
(h) kill -9 111
(i) sort < /etc/passwd > foo 2> err
(j) sort < foo > bar&
|