0% found this document useful (0 votes)
11 views14 pages

OS Practical 1-5.asw.123

The document provides an introduction to basic Linux commands and system calls for file, directory, and process management, detailing the structure of the Linux file system and various commands such as cat, rm, cp, and ps. It also includes the implementation of shell scripts and CPU scheduling algorithms like First Come First Serve (FCFS). Overall, it serves as a comprehensive guide for understanding and utilizing Linux commands effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views14 pages

OS Practical 1-5.asw.123

The document provides an introduction to basic Linux commands and system calls for file, directory, and process management, detailing the structure of the Linux file system and various commands such as cat, rm, cp, and ps. It also includes the implementation of shell scripts and CPU scheduling algorithms like First Come First Serve (FCFS). Overall, it serves as a comprehensive guide for understanding and utilizing Linux commands effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Experiment No.

01
AIM: Introduction of basic Linux Commands and system calls for file, directory, and process
management.

LINUX:
Introduction :
LINUX operating system
LINUX is an operating system which was first developed in the 1960s, and has been under
constant development ever since. By operating system, we mean the suite of programs which
make the computer work. It is a stable, multi-user, multi-tasking system for servers, desktops
and laptops. LINUX systems also have a graphical user interface (GUI) similar to Microsoft
Windows which provides an easy to use environment. However, knowledge of LINUX is
required for operations which aren't covered by a graphical program, or for when there is no
windows interface available, for example, in a telnet session. There are many different
versions of LINUX, although they share common similarities. The most popular varieties of
LINUX are Sun Solaris, GNU/Linux, and MacOS X.
Structure of LINUX file system –

All the files are grouped together in the directory structure. The file-system is arranged in a
hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally called
root (written as a slash /)

etc – Administrative programs and configuration files


dev – Devices drivers (pointers) such as disk drives, keyboard, mouse, etc.
var – Temporary administrative space for logging and other system information
home – Home directories for users
usr – Standard programs and code libraries
/usr/sbin –Administrative programs
/usr/bin – Standard executable programs
/usr/lib – Code libraries
/usr/local/bin – Additional programs
Features of LINUX operating system –
1) Multitasking: Multitasking is the capability of the operating system to perform various
tasks.ie. A single user can perform various tasks. Multiuser capabilities. This allows several
users to use the same computer to perform their tasks.
2) Security: Every user have a login name and password So, accessing another user’s data is
impossible without permission
3) Portability: LINUX is portable because it is written in a high level language. So LINUX
can be run on different computers.
4) Communication: LINUX supports the following communications.
i) Between the different terminals connected to the LINUX server.
ii) Between the users of one computer to the users of another.
5) Programming facility: LINUX is highly programmable, the LINUX shell programming
language has all the necessary ingredients like conditional and control structures (Loops) and
variables.

LINUX Architecture –
Here is a basic block diagram of a LINUX system –

The main concept that unites all versions of LINUX is the following four basics –
 Kernel: The kernel is the heart of the operating system. It interacts with hardware and most
of the tasks like memory management, task scheduling and file management.
 Shell: The shell is the utility that processes your requests. When you type in a command at
your terminal, the shell interprets the command and calls the program that you want. The
shell uses standard syntax for all commands. C Shell, Bourne Shell and Korn Shell are most
famous shells which are available with most of the LINUX variants.
 Commands and Utilities: There are various command and utilities which you would use in
your day to day activities. cp, mv, cat and grep etc. are few examples of commands and
utilities. There are over 250 standard commands plus numerous others provided through 3rd
party software. All the commands come along with various optional options.
 Files and Directories: All data in LINUX is organized into files. All files are organized into
directories. These directories are organized into a tree-like structure called the file system.
Basic Linux Commands
Cat Command: cat linux command concatenates files and print it on the standard output.
1.To Create a new file:
cat > file1.txt
This command creates a new file file1.txt. After typing into the file press control+d(^d)
simultaneously to end
the file.
2.To Append data into the file: To append data into the same file use append operator >> to
write into thefile,
else the file will be overwritten (i.e., all of its contents will be erased).
cat >> file1.txt
3.To display a file: This command displays the data in the file.cat file1.txt
4.To concatenate several files and display:
cat file1.txt file2.txt
The above cat command will concatenate the two files (file1.txt and file2.txt) and it will
display the output in the screen. Some times the output may not fit the monitor screen. In
such situation you canprint those files in a new file or display the file using less command.
cat file1.txt file2.txt | less
5.To concatenate several files and to transfer the output to another file.
cat file1.txt file2.txt > file3.txt
In the above example the output is redirected to new file file3.txt
rmCOMMAND:
rm linux command is used to remove/delete the file from the directory.
6.To Remove / Delete a file:
Here rm command will remove/delete the file file1.txt.rm file1.txt
7.To delete a directory tree:
rm -ir tmp
This rm command recursively removes the contents of all subdirectories of the tmp
directory,prompting you regarding the removal of each file, and then removes the tmp
directory itself.
8.To remove more files at once:
rm command removes file1.txt and file2.txt files at the same time.rm file1.txt file2.txt
9.cd COMMAND:
cd command is used to change the directory.
cd linux-command
This command will take you to the sub-directory(linux-command) from its parent directory.

Ex:
cd ..
This will change to the parent-directory from the current working directory/sub-directory.
cd ~
This command will move to the user's home directory which is "/home/username".
10.cp COMMAND:
cp command copy files from one location to another. If the destination is an existing file, then
the file is overwritten; if the destination is an existing directory, the file is copied into the
directory (the directory is not overwritten).
11.Copy two files:
cp file1.txt file2.txt
The above cp command copies the content of file1.txt to file2.txt
12.ls COMMAND:
ls command lists the files and directories under current working directory.
Display root directorycontents:
ls /lists the contents of root directory.
13.Display hidden files and directories:
ls –a lists all entries including hidden files and directories.
14.Display I node information:
ls –i
15.ln COMMAND:
ln command is used to create link to a file (or) directory. It helps to provide soft link for
desired files.
Inode will be different for source and destination.
ln -s file1.txt file2.txt
Creates a symbolic link to 'file1.txt' with the name of 'file2.txt'. Here inode for 'file1.txt' and
'file2.txt'will be different.
16. mkdir command: Use this command to create one or more new directories.
Include one or more instances of the “<DIRECTORY” variable (separating each with a
whitespace), and seteach to the complete path to the new directory to be created.
mkdir OPTION

mdir command:
mv command:
diff command:
comm command:
wc command:

PROCESS UTILITIES:
ps Command: ps command is used to report the process status. ps is the short name for
Process Status.
1. ps: List the current running processes.
Output: PID TTY TIME CMD 2540 pts/1 00:00:00 bash
2. ps –f : Displays full information about currently running processes.
Output: UID PID PPID C STIME TTY TIME CMD nirmala 2540 2536 0 15:31 pts/1
00:00:00 bash
3. kill COMMAND: kill command is used to kill the background process.
Step by Step process:
• Open a process music player or any file.xmms press ctrl+z to stop the process.
• To know group id or job id of the background task.jobs -l It will list the background jobs
with its job id as,
• xmms 3956
• kmail 3467 To kill a job or process.
• kill 3956 kill command kills or terminates the background process xmms.

Conclusion: Hence we have implemented basic Linux Commands and system calls for file,
directory, and process management.

Experiment No.02
AIM: Implementation of Linux shell script commands.
Write a Shell Script that accepts a file name, starting and ending line numbers as Arguments
and displays all lines between the given line numbers.

ALGORITHM:
Step 1: Create a file with 5-6 lines of data
File can be created by vi sample.dat or cat sample.dat
Step 2:Now write a shell script with
vi 1.sh
step3:Check the no of arguments for shell script
if 0 arguments then print no arguments
else if 1 argument then print 1 argument
else if 2 arguments then print 2 arguments
else check for file is there or not(if file is not there print file does not exists)
1else sed -ne ''$2','$3' p' $1
sed is one of powerful filter(stream editor)
-e default option (script on command line)
-n suppresses automatic output
$2 first line number passed $3 2nd line number passed
p is a print command (prints current content to the pattern space).
$1 is name of file from which we are printing data between the line numbers.
Step 4:top
Script Name: 1sh
#!/bin/bash
if [ $# -lt 3 ]
then
else file echo "To execute you have to enter 3 arguments in command line in following
order..." echo " File
Name ,starting line number and ending line number..."
sed -n $2,$3p $1
Commands used in the script:
Sed command:
stream editor for filtering and transforming text
1. Replacing or substituting string
Sed command is mostly used to replace the text in a file. The below simple sed command
replaces the word "unix" with "linux" in the file.
$sed 's/unix/linux/' file.txt
2. Replacing the nth occurrence of a pattern in a line
$sed 's/unix/linux/2' file.txt
Replaces 2nd occurrence
3.printing pines for a given range
$sed –n 1,5p hello.txt
Prints first 5 lines in the file hello.txt
nl command:
The nl utility in Linux is used to give number lines of a file on console.
Example:
$ nl sort.txt
1 UK
2 Australia
3 Newzealand
4 Brazil
Execution:
5 America
check how many lines of data in the input file
root@localhost sh]# cat hello.txt | nl
1 abc
2 def
3 ghi
4 abc
5 abc
6 cccc
Executing Shell script:
run1:
[root@localhost sh]# sh 1.sh abc1.txt 2 4
def
ghi
abc
compare with the data in the file and output

Conclusion: We have successfully implemented Shell Script that accepts a file name, starting
and ending line numbers as Arguments and displays all lines between the given line numbers.

Experiment No.03
AIM: Implementation of basic commands of linux like ls, cp, mv.

Introduction:
"Linux commands" refer to the instructions or inputs that users provide to perform specific
operations in the Linux operating system. Linux, being a command-line-oriented operating
system, relies heavily on these commands for managing files, software, and system settings.
Linux is a popular open-source Unix-like operating system (OS). It is software that manages
a system’s hardware and resources. It is used in desktops, smartphones, laptops, enterprise
servers, and home appliances such as modems and routers. If you are considering using
Linux, then you need to be familiar with the basic Linux commands.
Basic Linux Commands With Syntax
Linux operating system has many commands. In this blog, we will take a look at the 20 most
important Linux commands that are commonly used by programmers and developers. These
commands will help you navigate through Linux operating system.
To gain hands-on knowledge of these commands, you will have to open the command line
first on your desktop or laptop. The Linux Command Line Interface (CLI) is a text-based
interface that will enable you to type text commands to instruct the computer to do specific
tasks. The Linux command line is case-sensitive.
Is Command
clear Command
pwd Command
cd Command
cp Command
mv Command
rm Command
rmdir Command
touch Command
locate Command
sudo Command
df Command
du Command
chown Command
echo Command
head Command
tail Command
uname Command
history Command
man Command
useradd Command
cat Command
ping Command

1.ls command
The ls command allows the user to view the contents of a directory. It lists the files and
directories. The ls command displays the contents of the current working directory by default
(if the user does not specify any other directory). To check the content of other directories,
you can type the ls command followed by the directory path.

ls command syntax
ls [Options] [File]
Some of the common option tags that you can use with the ls command:
Option Description
ls –R lists all the files in the sub-directories as well
ls –S sorts and lists all the contents in the specified directory by size
ls -al list the files and directories with detailed information
ls -a shows the hidden files in the specified directory
2.cp command
You can use the cp command to copy files from the current directory to a different directory.
cp source file destination file. In case you need a copy of the file second.txt in the same
directory you have to use the cp command.
cp command syntax
$ cp source file destination file
Example – to copy the contents of the red file into the blue file.
$ cp red.txt blue.txt
3.mv command
Use the mv command to move a file from a given directory to a different directory. It helps
programmers to organize data easily. You can also use this command to rename files. The file
or directory that is moved is deleted from the working directory.
mv command syntax – to move a file
$ mv <Filename> <Directory_Name>
mv command syntax – to rename a file
mv old_filename new_filename
rm command
The rm command deletes directories as well as the contents within them. This command
needs to be used carefully as it deletes everything.
rm command syntax
$ rm <filename>
rmdir command
rmdir allows users to delete a directory, provided that the directory is empty. You will need to
ensure that there is no file or subdirectory under the directory that you want to delete.
$ rmdir <directoryname>
touch command
With the touch command, you can create a new blank file with the given name.
touch command syntax
$ rmdir <directoryname>
You can also create multiple files simultaneously
$ touch <filename1> <filename2>

Conclusion: Hence we have studied and implemented Basic Linux Commands.


Experiment No.04
AIM: To write a c program to simulate the CPU scheduling algorithm First Come First
Serve (FCFS)
Introduction:
To calculate the average waiting time using the FCFS algorithm first the waiting time of the
first process is kept zero and the waiting time of the second process is the burst time of the
first process and the waiting time of the third process is the sum of the burst times of the first
and the second process and so on. After calculating all the waiting times the average waiting
time is calculated as the average of all the waiting times. FCFS mainly says first come first
serve the algorithm which came first will be served first.
ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process name and the burst time Step
Step 4: Set the waiting of the first process as ‗0‘and its burst time as its turnaround time Step
Step 5: for each process in the Ready Q calculate
a). Waiting time (n) = waiting time (n-1) + Burst time (n-1) b).
Turnaround time (n)= waiting time(n)+Burst time(n)
Step 6: Calculate
a) Average waiting time = Total waiting Time / Number of process
b) Average Turnaround time = Total Turnaround Time / Number of process
Step 7: Stop the process Page.
#include<stdio.h>
#include<conio.h>
main()
{
int bt[20], wt[20], tat[20], i, n;
float wtavg, tatavg;
clrscr();
printf("\nEnter the number of processes -- ");
scanf("%d", &n);
for(i=0;i<n;i++) {
printf("\nEnter Burst Time for Process %d -- ", i);
scanf("%d", &bt[i]); }
wt[0] = wtavg = 0;
tat[0] = tatavg = bt[0];
for(i=1;i<n;i++)
{
wt[i] = wt[i-1] +bt[i-1];
tat[i] = tat[i-1] +bt[i];
wtavg = wtavg + wt[i];
tatavg = tatavg + tat[i]; }
printf("\t PROCESS \tBURST TIME \t WAITING TIME\t TURNAROUND TIME\n");
for(i=0;i<n;i++)
printf("\n\t P%d \t\t %d \t\t %d \t\t %d", i, bt[i], wt[i], tat[i]);
printf("\nAverage Waiting Time -- %f", wtavg/n);
printf("\nAverage Turnaround Time -- %f", tatavg/n);
getch(); }
INPUT
Enter the number of processes -- 3
Enter Burst Time for Process 0 -- 24
Enter Burst Time for Process 1 -- 3
Enter Burst Time for Process 2 -- 3
OUTPUT
PROCESS BURST TIME WAITING TIME TURNAROUND
TIME
P0 24 0 24
P1 3 24 27
P2 3 27 30
Average Waiting Time-- 17.000000
Average Turnaround Time -- 27.000000
Conclusion: We have successfully studied and implemented CPU scheduling algorithm First
Come First Serve (FCFS)
Experiment No.05
AIM: To write a c program to simulate the preemptive scheduling algorithm Round Robin.
Introduction:
Our aim is to calculate the average waiting time. There will be a time slice, each process
should be executed within that time-slice and if not it will go to the waiting state so first
check whether the burst time is less than the time-slice. If it is less than it assign the waiting
time to the sum of the total times. If it is greater than the burst-time then subtract the time slot
from the actual burst time and increment it by time-slot and the loop continues until all the
processes are completed.
ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue and time quantum (or) time slice
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Calculate the no. of time slices for each process where No. of time slice for process
(n) = burst time process (n)/time slice
Step 5: If the burst time is less than the time slice then the no. of time slices =1.
Step 6: Consider the ready queue is a circular Q, calculate
a) Waiting time for process (n) = waiting time of process(n-1)+ burst time of
process(n-1 ) + the time difference in getting the CPU from process(n-1)
b) Turnaround time for process(n) = waiting time of process(n) + burst time of process(n)+
the time difference in getting CPU from process(n).
Step 7: Calculate
c) Average waiting time = Total waiting Time / Number of process
d) Average Turnaround time = Total Turnaround Time / Number of process Step
8: Stop the process
SOURCE CODE
#include<stdio.h>
main()
{
int i,j,n,bu[10],wa[10],tat[10],t,ct[10],max;
float awt=0,att=0,temp=0;
clrscr();
printf("Enter the no of processes -- ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter Burst Time for process %d -- ", i+1);
scanf("%d",&bu[i]);
ct[i]=bu[i]; }
printf("\nEnter the size of time slice -- ");
scanf("%d",&t);
max=bu[0];
for(i=1;i<n;i++)
if(max<bu[i])
max=bu[i];
for(j=0;j<(max/t)+1;j++)
for(i=0;i<n;i++)
if(bu[i]!=0)
if(bu[i]<=t) {
tat[i]=temp+bu[i];
temp=temp+bu[i];
bu[i]=0;
}
else {
bu[i]=bu[i]-t;
temp=temp+t;
}
for(i=0;i<n;i++){
wa[i]=tat[i]-
ct[i]; att+=tat[i];
awt+=wa[i];}
printf("\nThe Average Turnaround time is -- %f",att/n);
printf("\nThe Average Waiting time is -- %f ",awt/n);
printf("\n\tPROCESS\t BURST TIME \t WAITING TIME\tTURNAROUND TIME\n");
for(i=0;i<n;i++)
printf("\t%d \t %d \t\t %d \t\t %d \n",i+1,ct[i],wa[i],tat[i]);
getch();}
INPUT:
Enter the no of processes – 3
Enter Burst Time for process 1 – 24
Enter Burst Time for process 2 -- 3
Enter Burst Time for process 3 – 3
Enter the size of time slice – 3
OUTPUT:
PROCESS BURST TIME WAITING TIME TURNAROUNDTIME
1 24 6 30
2347
3 3 7 10
The Average Turnaround time is – 15.666667
The Average Waiting time is ------------ 5.666667

Conclusion: hence we have successfully implemented a c program to simulate the


preemptive scheduling algorithm Round Robin.

You might also like