0% found this document useful (0 votes)
7 views24 pages

Practical

The document contains practical exercises for T.Y(IT) students focusing on various Unix commands, programming in C/C++, and process scheduling algorithms such as FCFS, SJF, and Round-Robin. Each practical includes aims, source codes, and expected outputs for tasks like compiling and running programs, studying IPC mechanisms, and implementing scheduling algorithms. The document serves as a comprehensive guide for students to understand and apply these concepts in a Linux environment.

Uploaded by

naganekishor7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views24 pages

Practical

The document contains practical exercises for T.Y(IT) students focusing on various Unix commands, programming in C/C++, and process scheduling algorithms such as FCFS, SJF, and Round-Robin. Each practical includes aims, source codes, and expected outputs for tasks like compiling and running programs, studying IPC mechanisms, and implementing scheduling algorithms. The document serves as a comprehensive guide for students to understand and apply these concepts in a Linux environment.

Uploaded by

naganekishor7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Practical – 01

Name : Vilas Balwan Suryawanshi


Class:T.Y(IT)
PRN : 2221291246015 Roll No :
13

AIM : To Study Basic Unix Commands

Different types of commands :


The Ubuntu Terminal is a command-line interface (CLI)
in Ubuntu (a Linux operating system).
It lets you communicate directly with the computer by
typing text commands instead of clicking buttons.
It's powerful because you can control almost everything
— installing programs, managing files, updating the
system, and even programming tasks.
Ubuntu Commands:
.date : Shows the current date and time.
 cal : Displays a calendar of the current month by
default. You can also view other months/years.
 ls: List files and directories in the current directory.
 pwd: Print the current working directory's path.
 cd: Change the current directory.
 mkdir: Create a new directory.
 rmdir: Remove an empty directory.
 cp: Copy files or directories
 mv: Move or rename files or directories.date
 rm: Remove files or directories.
 touch: Create a new empty file.
 cat: Display the contents of a file.

Networking Commands :
 ping: Test network connectivity to a host.
 ifconfig: Display network interface information.
 traceroute: Trace the route packets take to reach a
destination.
 wget: Download files from the internet.

Text Searching & Manipulation:


 grep: Search for text patterns in files.
 sed: Stream editor for text manipulation.

 awk: Pattern scanning and processing tool.

Permissions & Ownership:


 sudo: Execute a command with superuser privileges.
 chmod: Change file or directory permissions.
 chown: Change file or directory ownership.

System Information & Monitoring:


 whoami: Display the current user's username.
 uname: Display system information, including kernel
version.
 df: Display disk space usage.
 dmesg: Show kernel log messages.
 ps: List currently running processes.
 kill: Terminate a process.
 top: Display a live view of running processes and
system usage.
 OUTPUT:
Practical – 02
Name : Vilas Balwan Suryawanshi
Class:T.Y(IT)
PRN : 2221291246015 Roll No : 13

AIM : How to Compile and Run C,C++ prog. On Ubuntu


Terminal

Steps To Run Program :

Open the Terminal: The terminal can be opened by


pressing Ctrl + Alt +T.
Write the C code: Using a text editor, create a file with
a .c extension, for example my_program.c, and write the
C code inside.

#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>

int main()
{
fork();
printf("\n Hello World");
}

Save the file: Save the file in a directory you can easily
access through the terminal.
Compile the code: In the terminal, navigate to the
directory where you saved the file using
the cd command. Then, compile the C code using
the gcc compiler:

Code :

gcc fork.c -o fork


This command compiles my_program.c and creates an
executable file named my_program in the same
directory.

Run the executable: Execute the compiled program by


typing:
This command runs the executable file, and the output
of the program ("Hello, world!") will be displayed in the
terminal.

Code :

./a.out

This command runs the executable file, and the output


of the program (Hello world) will be displayed in the
terminal.

CODE:
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>

int main()
{
fork();
fork();
fork();
printf("\n Hello World");
}

OUTPUT:
Practical – 03

Name : Ganesh Shrikant Munde Class:T.Y(IT)


PRN : 2221291246048 Roll No :
44
AIM : TO STUDY IPC MECHANISM
CODE:
#include <stdio.h>

int main() {
int i, n, time = 0, remain;
int bt[10], rt[10], quantum;

printf("Enter total number of processes: ");


scanf("%d", &n);
remain = n;

for (i = 0; i < n; i++) {


printf("Enter Burst Time for Process %d: ", i + 1);
scanf("%d", &bt[i]);
rt[i] = bt[i];
}

printf("Enter Time Quantum: ");


scanf("%d", &quantum);
int wt[10] = {0}, tat[10] = {0};

while (remain > 0) {


for (i = 0; i < n; i++) {
if (rt[i] > 0) {
if (rt[i] > quantum) {
time += quantum;
rt[i] -= quantum;
} else {
time += rt[i];
wt[i] = time - bt[i];
rt[i] = 0;
remain--;
}
}
}
}

printf("\nProcess\tBurst Time\tWaiting Time\


tTurnaround Time\n");

for (i = 0; i < n; i++) {


tat[i] = bt[i] + wt[i];
printf("P%d\t%d\t\t%d\t\t%d\n", i + 1, bt[i], wt[i],
tat[i]);
}
return 0;
}

OUTPUT:
Practical – 04

Name : Ganesh Shrikant Munde Class:T.Y(IT)


PRN : 2221291246048 Roll No :
44
Aim :to study fork system call
Code: #include <stdio.h>

int main() {
int n, i, j;

// Input number of processes


printf("Enter number of processes: ");
scanf("%d", &n);

int bt[n], p[n], priority[n];


int wt[n], tat[n];

// Input burst time and priority


for(i = 0; i < n; i++) {
printf("Enter burst time and priority for process
%d: ", i + 1);
scanf("%d%d", &bt[i], &priority[i]);
p[i] = i + 1;
}
// Sort by priority (lower number = higher priority)
for(i = 0; i < n; i++) {
for(j = i + 1; j < n; j++) {
if(priority[j] < priority[i]) {
// Swap priority
int temp = priority[i];
priority[i] = priority[j];
priority[j] = temp;

// Swap burst time


temp = bt[i];
bt[i] = bt[j];
bt[j] = temp;

// Swap process number


temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}
}

// Calculate waiting time


wt[0] = 0;
for(i = 1; i < n; i++) {
wt[i] = wt[i-1] + bt[i-1];
}

// Calculate turnaround time


for(i = 0; i < n; i++) {
tat[i] = wt[i] + bt[i];
}

// Output
printf("\nProcess\tBT\tPriority\tWT\tTAT\n");
for(i = 0; i < n; i++) {
printf("%d\t%d\t%d\t\t%d\t%d\n", p[i], bt[i],
priority[i], wt[i], tat[i]);
}

return 0;
}
Practical – 05

Name : Ganesh Shrikant Munde Class:T.Y(IT)


PRN : 2221291246048 Roll No :
44

AIM : To Study FCFS Scheduling

Steps to Study FCFS Scheduling :


User Input:

Number of processes (n)

Execution time (exetime[i]) for each process

Processing:

Calculates waiting time and turnaround time using FCFS (where WT of


process i = sum of burst times of all previous processes).

Output:

A table showing Process ID, Burst Time, Waiting Time, and Turnaround
Time

Average waiting time and turnaround time

Code :
#include<stdio.h>

int main()
{
int n,exetime[100],i;
int wtime = 0 , tat = 0;
float awt = 0 , atat = 0 , _awt = 0, _atat = 0;
printf("\n Enter the no of process = ");
scanf("%d",&n);

for(i=0;i<n;i++)
{
printf("Enter the execution time for each process = ");
scanf("%d",&exetime[i]);
}
printf("\n \n pid \t \t BT \t \t WT \t \t TAT");

for(i=0;i<n;i++)
{
tat = exetime[i] + wtime;
printf("\n %d \t \t %d \t \t %d \t \t %d", i+1 , exetime[i] , wtime , tat);
_awt = _awt + wtime;
_atat = _atat + tat;
wtime = wtime + exetime[i];
}
awt=_awt/n;
atat=_atat/n;
printf("\n Avg.waiting time %f",awt);
printf("\n Avg.turnaround time %f ",atat);
}

OUTPUT:
Practical – 06

Name : Vilas Balwan Suryawanshi Class:T.Y(IT)


PRN : 2221291246015 Roll No :
13

AIM : To Study SJF Scheduling

Steps To Study SJF Scheduling :


User Input:

Number of processes (n)

Execution time (exetime[i]) for each process

Processing:

Firstly it will sort the array by the decreasing order of the


processes and then Calculates waiting time and turnaround
time using SJF (where WT of process i = sum of burst times
of all previous processes).

Output:

A table showing Process ID, Burst Time, Waiting Time, and


Turnaround Time

Average waiting time and turnaround time.

CODE :

#include<stdio.h>

int main()
{
int n,exetime[100],i;
int wtime = 0 , tat = 0;
float awt = 0 , atat = 0 , _awt = 0, _atat = 0;
printf("\n Enter the no of process = ");
scanf("%d",&n);

for(i=0;i<n;i++)
{
printf("Enter the execution time for each process = ");
scanf("%d",&exetime[i]);
}
for(i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
If(exetime[i] < exetime[j])
{
int temp = exetime[i];
exetime[i] = exetime[j];
exetime[j] = temp;
}
}
}
printf("\n \n pid \t \t BT \t \t WT \t \t TAT");

for(i=0;i<n;i++)
{
tat = exetime[i] + wtime;
printf("\n %d \t \t %d \t \t %d \t \t %d", i+1 , exetime[i] ,
wtime , tat);
_awt = _awt + wtime;
_atat = _atat + tat;
wtime = wtime + exetime[i];
}
awt=_awt/n;
atat=_atat/n;
printf("\n Avg.waiting time %f",awt);
printf("\n Avg.turnaround time %f ",atat);
}
OUTPUT :
Practical – 07

Name : Vilas Balwan Suryawanshi


Class:T.Y(IT)
PRN : 2221291246015 Roll No : 13
AIM :TO STUDY PRIORITY SCHEDULING

SOURCE CODE:
#include <stdio.h>

int main() {
int n, i, j;

// Input number of processes


printf("Enter number of processes: ");
scanf("%d", &n);

int bt[n], p[n], priority[n];


int wt[n], tat[n];

// Input burst time and priority


for(i = 0; i < n; i++) {
printf("Enter burst time and priority for process
%d: ", i + 1);
scanf("%d%d", &bt[i], &priority[i]);
p[i] = i + 1;
}

// Sort by priority (lower number = higher priority)


for(i = 0; i < n; i++) {
for(j = i + 1; j < n; j++) {
if(priority[j] < priority[i]) {
// Swap priority
int temp = priority[i];
priority[i] = priority[j];
priority[j] = temp;

// Swap burst time


temp = bt[i];
bt[i] = bt[j];
bt[j] = temp;

// Swap process number


temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}
}

// Calculate waiting time


wt[0] = 0;
for(i = 1; i < n; i++) {
wt[i] = wt[i-1] + bt[i-1];
}

// Calculate turnaround time


for(i = 0; i < n; i++) {
tat[i] = wt[i] + bt[i];
}

// Output
printf("\nProcess\tBT\tPriority\tWT\tTAT\n");
for(i = 0; i < n; i++) {
printf("%d\t%d\t%d\t\t%d\t%d\n", p[i], bt[i],
priority[i], wt[i], tat[i]);
}

return 0;
}
OUTPUT:
Practical – 08

Name : Vilas Balwan Suryawanshi


Class:T.Y(IT)
PRN : 2221291246015 Roll No : 13

AIM :TO Study Round-RobinScheduling :


User Input:

Number of processes (n)

Execution time (exetime[i]) for each process

Processing:

Firstly it will sort the array by the decreasing order of the


processes and then Calculates waiting time and turnaround
time using SJF (where WT of process i = sum of burst times
of all previous processes).

Output:

A table showing Process ID, Burst Time, Waiting Time, and


Turnaround Time

Average waiting time and turnaround time.

CODE:
#include <stdio.h>

int main() {
int i, n, time = 0, remain;
int bt[10], rt[10], quantum;

printf("Enter total number of processes: ");


scanf("%d", &n);
remain = n;

for (i = 0; i < n; i++) {


printf("Enter Burst Time for Process %d: ", i + 1);
scanf("%d", &bt[i]);
rt[i] = bt[i];
}

printf("Enter Time Quantum: ");


scanf("%d", &quantum);

int wt[10] = {0}, tat[10] = {0};

while (remain > 0) {


for (i = 0; i < n; i++) {
if (rt[i] > 0) {
if (rt[i] > quantum) {
time += quantum;
rt[i] -= quantum;
} else {
time += rt[i];
wt[i] = time - bt[i];
rt[i] = 0;
remain--;
}
}
}
printf("\nProcess\tBurst Time\tWaiting Time\
tTurnaround Time\n"); for (i = 0; i < n; i++) {
tat[i] = bt[i] + wt[i];
printf("P%d\t%d\t\t%d\t\t%d\n", i + 1, bt[i], wt[i],
tat[i]);
}

return 0;
}

OUTPUT:

You might also like