IGNOU ASSIGNMENT CS-02

     
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
 
 
 
 
 
 

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)
CPU Time
End Time (Turnaround Time)
(Start Time + CPU Time)
 
Average Waiting Time
Average Turnaround Time
 
SJF:-
 
JOB4
JOB5
JOB1
JOB2
JOB3
Start Time (Waiting Time)
CPU Time
End Time (Turnaround Time)
(Start Time + CPU Time)
 
Average Waiting Time
Average Turnaround Time
   
  Round Robin:Round Robin algorithm takes control from the process after a fixed interval and gives it to the another one.
 
 
Quantum Number
CPU Time Used
CPU Time Left

 
Quantum Number
CPU Time Used
CPU Time Left
 
 
JOB1
JOB2
JOB3
JOB4
JOB5
Turnaround Time
CPU Time
Waiting Time
 
Average Waiting Time
Average Turnaround Time
   
Question 3

Compare and contrast the features of UNIX and LINUX operating systems.

 
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&