[go: up one dir, main page]

0% found this document useful (0 votes)
22 views15 pages

OS Practicals

The document provides an overview of using the Ubuntu Terminal, including basic commands for file management, networking, text manipulation, permissions, and system monitoring. It also outlines steps to compile and run C programs, specifically demonstrating FCFS and SJF scheduling algorithms with example code. Additionally, it includes input/output processes and calculations for average waiting and turnaround times for scheduling tasks.

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)
22 views15 pages

OS Practicals

The document provides an overview of using the Ubuntu Terminal, including basic commands for file management, networking, text manipulation, permissions, and system monitoring. It also outlines steps to compile and run C programs, specifically demonstrating FCFS and SJF scheduling algorithms with example code. Additionally, it includes input/output processes and calculations for average waiting and turnaround times for scheduling tasks.

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/ 15

Practical – 01

Name : Kasbe Krushna Dnyanoba


PRN : 2221291246021 Roll No : 18
Class : TY(IT)

Terminal
 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

 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.
 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.
 uptime: Display system uptime and load average.
Output :
AIM : How to Compile and Run C,C++ prog. On Ubuntu
Terminal

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

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

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.

Output :
AIM : To Study FCFS Scheduling

Program :

#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);
}
Steps

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

Process 1 (i = 0)
exetime[0] = 24

wtime = 0 (no previous process)

tat = wtime + exetime[0] = 0 + 24 = 24

Add to totals:

_awt += 0 → _awt = 0

_atat += 24 → _atat = 24

Update wtime for next process:

wtime += 24 → wtime = 24

Process 2 (i = 1)
exetime[1] = 3

wtime = 24
tat = 24 + 3 = 27

Add to totals:

_awt += 24 → _awt = 24

_atat += 27 → _atat = 51

Update wtime:

wtime += 3 → wtime = 27

Process 3 (i = 2)
exetime[2] = 3

wtime = 27

tat = 27 + 3 = 30

Add to totals:

_awt += 27 → _awt = 51

_atat += 30 → _atat = 81

Update wtime:

wtime += 3 → wtime = 30

Averages :
awt = _awt / n = 51 / 3 = 17.0

atat = _atat / n = 81 / 3 = 27.0

pid BT WT TAT

1 24 0 24

2 3 24 27

3 3 27 30

Avg.waiting time: 17.000000


Avg.turnaround time: 27.000000

Output :
AIM : To Study SJF Scheduling

Program :
#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);
}

Steps

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.

Step-by-Step Walkthrough of the Sorting:

1. First pass through outer loop (i = 0)

The outer loop starts with the first element of the array. For each element, the inner
loop compares it with all the subsequent elements and swaps if necessary.

i = 0, exetime[0] = 3

Compare exetime[0] = 3 with exetime[1] = 24:

Since 3 < 24, we swap them.


Array after swap: [24, 3, 3]

Compare exetime[0] = 24 with exetime[2] = 3:

Since 24 > 3, no swap is needed.

After the first outer loop pass, the array is:

Exetime[] = {24 3 3}

2.Second pass through outer loop (i = 1)

Now, we move to the second element (exetime[1] = 3) and compare it with the
last remaining element.

i = 1, exetime[1] = 3

Compare exetime[1] = 3 with exetime[2] = 3:

Since 3 == 3, no swap is needed.

After the second pass, the array is:

Exetime[] = {24 3 3}

No more swaps needed


Since the array is already sorted in decreasing order, the outer loop terminates,
and the sorted array remains:

Process 1 (i = 0)
exetime[0] = 24

wtime = 0 (no previous process)

tat = wtime + exetime[0] = 0 + 24 = 24

Add to totals:
_awt += 0 → _awt = 0

_atat += 24 → _atat = 24

Update wtime for next process:

wtime += 24 → wtime = 24

Process 2 (i = 1)
exetime[1] = 3

wtime = 24

tat = 24 + 3 = 27

Add to totals:

_awt += 24 → _awt = 24

_atat += 27 → _atat = 51

Update wtime:

wtime += 3 → wtime = 27

Process 3 (i = 2)
exetime[2] = 3

wtime = 27

tat = 27 + 3 = 30

Add to totals:

_awt += 27 → _awt = 51

_atat += 30 → _atat = 81

Update wtime:

wtime += 3 → wtime = 30
Averages :
awt = _awt / n = 51 / 3 = 17.0

atat = _atat / n = 81 / 3 = 27.0

pid BT WT TAT

1 24 0 24

2 3 24 27

3 3 27 30

Avg.waiting time: 17.000000

Avg.turnaround time: 27.000000

Output :

You might also like