Osc Lab Record
Osc Lab Record
Subject Name:
Subject Code:
Semester:
Name:
Registration No.:
Program/Branch:
Specialization:
Academic Year:
Campus:
CENTURION UNIVERSITY OF TECHNOLOGY AND MANAGEMENT
ODISHA
Certificate
This is to certify that Mr./Ms. ............................................................................ having
requirements.
Of)ice Seal
INDEX
Sl. Page Faculty
Date Name of the Experiment Remark
No. No. Signature
1 Copy from one to another file
using unbuffered I/O system
2 Gaining Root privilege with
su and sudo
3 Login to remote system
through SSH
4 Demonstrate of Hierarchical
File System in Linux
5 Controlling Access to files
with ACL
6 Create, Edit, Save and Exit
using Vim by using VM Box
7 Write a script to demonstrate
decision making, loop control,
Arrays
8 Write a program to simulate
the following CPU scheduling
Algorithm [Round Robin]
9 Write a program to simulate
Banker’s Algorithm for
DeadLock prevention
10 Write a program to simulate
page replacement algorithm
[FIFO]
School: ............................................................................................................. Campus: .......................................................
Date: .....................................
The "root" user account on Linux has full administrative privileges over the entire system. If
you want to edit system configuration files, install software, add users, or virtually anything
else outside of your home directory, you'll need root access. For most tasks, you won't need
to log or switch to the root user account—you can run your administrative tasks with
the sudo command to run them as root. This prevents you from doing damage while logged
in with full superuser permissions. If you're using Ubuntu, the root account is locked by
default to prevent this from happening. But if you need to keep root access while doing a
large amount of system tasks, you can enable the root user and become root with
the su command, or by signing in as root on console
Type .sudo passwd root and press ↵ Enter. When prompted for a password, enter
your user password
Lock the root account again. If you want to lock the root account, enter the following
command to remove the password and lock root:
sudo passwd -dl root
Type .su - and press ↵ Enter. This will attempt to log you in as "super user." You can
actually use this command to log in as any user on the machine, but when left blank it will
attempt to log in as root
Enter the root password when prompted. After typing "su -" and pressing Enter. You'll be
prompted for the root password.
If you get an "authentication error" message, your root account is likely locked. You will
need to unlock the root account.
Enter the commands that require root access. Once you've used su - to log in
as root, you can run any commands that require root access. The su command is
preserved until the end of the session, so you don't need to keep re-entering the
root password every time you need to run a command
Tar was initially released in January 1979 and has since evolved into the
standard file archiver on Linux. As of writing this article in November 2020,
the latest stable version of tar was released on February 23, 2019 and therefore
is still in active development to this day.
If tar is not on your system already, go ahead and install it via your Linux
distribution’s package manager:
$ sudo pacman -S tar # Arch
$ sudo apt install tar # Debian and Ubuntu
$ sudo dnf install tar # CentOS and Fedora
I won’t dive into the intricacies of how tar works under the hood too much in
this article, but I will mention some important points to be aware of as we
progress through the commands in subsequent sections.
Compression Tools
There are quite a few compression tools available on Linux, with each one
implementing a specific compression algorithm. The compression tools
introduced in this article all have a very similar command line interface and
usage pattern, which means that if you know how to use one of the tools, you
can use them all.
Go ahead and install the gzip, bzip2, xz and zstd compression tools via your
Linux distribution’s package manager:
$ sudo pacman -S gzip bzip2 xz zstd # Arch
$ sudo apt install gzip bzip2 xz-utils zstd # Debian and Ubuntu
$ sudo dnf install gzip bzip2 xz zstd # Fedora
ssh-keygen -t rsa
2. You will be prompted to supply a filename (for saving the key pair) and a password
(for protecting your private key):
o Filename: To accept the default filename (and location) for your key pair,
press Enter or Return without entering a filename.
o Password: Enter a password that contains at least five characters, and then
press Enter or Return. If you press Enter or Return without entering a password,
your private key will be generated without password-protection.
Important:
If you don't password-protect your private key, anyone with access to your
computer conceivably can SSH (without being prompted for a password) to your
account on any remote system that has the corresponding public key
You'll be prompted for your account password. Your public key will be copied to your home
directory (and saved with the same filename) on the remote system.
2. Log into the remote system using your account username and password.
Note:
If the remote system is not configured to support password-based authentication, you will need to ask
system administrators to add your public key to the ~/.ssh/authorized_keys file in your account (if your
account doesn't have ~/.ssh/authorized_keys file, system administrators can create one for you). Once
your public key is added to your ~/.ssh/authorized_keys file on the remote system, the setup process is
complete, and you should now be able to SSH to your account from the computer that has your
private key.
3. If your account on the remote system doesn't already contain a ~/.ssh/authorized_keys file, create one;
on the command line, enter the following commands:
4. mkdir -p ~/.ssh
5. touch ~/.ssh/authorized_keys
Note:
If your account on the remote system already has a ~/.ssh/authorized_keys file, executing these
commands will not damage the existing directory or file.
6. On the remote system, add the contents of your public key file (for example, ~/id_rsa.pub) to a new
line in your ~/.ssh/authorized_keys file; on the command line, enter:
You may want to check the contents of ~/.ssh/authorized_keys to make sure your public key was added
properly; on the command line, enter:
more ~/.ssh/authorized_keys
7. You may now safely delete the public key file (for example, ~/id_rsa.pub) from your account on the
remote system; on the command line, enter:
rm ~/id_rsa.pub
Alternatively, if you prefer to keep a copy of your public key on the remote system, move it to
your .ssh directory; on the command line, enter:
mv ~/id_rsa.pub ~/.ssh/
o If your private key is not password-protected, the remote system will place you on the
command line in your home directory without prompting you for a password or
passphrase:
If the private key you're using does not have the default name, or is not stored in the default
path (not ~/.ssh/id_rsa), you must explicitly invoke it in one of two ways:
o On the SSH command line: Add the -i flag and the path to your private key.
o In an SSH client configuration file: SSH gets configuration data from the following
sources (in this order):
1. From command-line options
2. From the user's client configuration file (~/.ssh/config), if it exists
3. From the system-wide client configuration file (/etc/ssh/ssh_config)
The SSH client configuration file is a text file containing keywords and arguments. To
specify which private key should be used for connections to a particular remote host,
use a text editor to create a ~/.ssh/config that includes
the Host and IdentityFile keywords.
You can add multiple Host and IdentityFile directives to specify a different private key for
each host listed; for example:
Host host2.somewhere.edu
IdentityFile ~/.ssh/old_keys/host2_key
Host host4.somewhere.edu
IdentityFile ~/.ssh/old_keys/host4_key
Host host6.somewhere.edu
IdentityFile ~/.ssh/old_keys/host6_key
Alternatively, you can use a single asterisk ( * ) to provide global defaults for all hosts
(specify one private key for several hosts); for example:
Host *.somewhere.edu
IdentityFile ~/.ssh/old_keys/all_hosts_key
The ps (process statuses) command produces a snapshot of all running processes. Therefore,
unlike the Windows task manager, the results are static.
When this command is used without any additional argument or option, it will return a list of
running processes along with four crucial columns: the PID, terminal name (TTY), running
time (TIME), and the name of the command that launches the process (CMD). You can
use ps aux to get more in-depth information about your running processes. Here’s a
breakdown of each argument:
If you want to list Linux processes in a hierarchical view, use the ps -axjf command. In this
format, the shell will put child processes under their parent processes. Aside from those two
options, here are some other common examples of the ps command that list running
processes in Linux:
Unlike the ps command, the output of the top command is updated periodically. That
means you’ll see real-time updates for CPU usage and running time
Algorithm
Step 3 − Retrieve the message from the pipe and write it to the standard output.
Step 5 − Retrieve the message from the pipe and write it to the standard output.
Note − Retrieving messages can also be done after sending all messages.
• Read: This permission give you the authority to open and read a file. Read permission
on a directory gives you the ability to lists its content.
• Write: The write permission gives you the authority to modify the contents of a file.
The write permission on a directory gives you the authority to add, remove and rename
files stored in the directory. Consider a scenario where you have to write permission
on file but do not have write permission on the directory where the file is stored. You
will be able to modify the file contents. But you will not be able to rename, move or
remove the file from the directory.
• Execute: In Windows, an executable program usually has an extension “.exe” and
which you can easily run. In Unix/Linux, you cannot run a program unless the execute
permission is set. If the execute permission is not set, you might still be able to
see/modify the program code(provided read & write permissions are set), but not run
it.
File Permissions in Linux/Unix
Let’s see file permissions in Linux with examples:
ls – l on terminal gives
ls - l
Here, we have highlighted ‘-rw-rw-r–‘and this weird looking code is the one that tells
us about the Unix permissions given to the owner, user group and the world.
Here, the first ‘–‘ implies that we have selected a file.p>
1. Absolute mode
2. Symbolic mode
Permission
Number Symbol
Type
0 No Permission —
1 Execute –x
2 Write -w-
3 Execute + Write -wx
4 Read r–
5 Read + Execute r-x
6 Read +Write rw-
Read + Write
7 rwx
+Execute
In the above-given terminal window, we have changed the permissions of the file
‘sample to ‘764’.
• The file /etc/group contains all the groups defined in the system
• You can use the command “groups” to find all the groups you are a member o
• You can use the command newgrp to work as a member a group other than your default
group
What is ACL ?
Access control list (ACL) provides an additional, more flexible permission mechanism for file
systems. It is designed to assist with UNIX file permissions. ACL allows you to give permissions
for any user or group to any disc resource.
Use of ACL :
Think of a scenario in which a particular user is not a member of group created by you but still
you want to give some read or write access, how can you do it without making user a member of
group, here comes in picture Access Control Lists, ACL helps us to do this trick.
Basically, ACLs are used to make a flexible permission mechanism in Linux.
From Linux man pages, ACLs are used to define more fine-grained discretionary access rights
for files and directories.
setfacl and getfacl are used for setting up ACL and showing ACL respectively.
For example :
getfacl test/declarations.h
Output:
# file: test/declarations.h
# owner: mandeep
# group: mandeep
user::rw-
group::rw-
other::r--
List of commands for setting up ACL :
1) To add permission for user
setfacl -m "u:user:permissions" /path/to/file
3) To allow all files or directories to inherit ACL entries from the directory it is within
setfacl -dm "entry" /path/to/dir
Example :
setfacl -m u:mandeep:r-x test/declarations.h
See below image for output :
View ACL :
To show permissions :
# getfacl filename
Observe the difference between output of getfacl command before and after setting up
ACL permissions using setfacl command.
There is one extra line added for user mandeep which is highlighted in image above.
Output:
change permissions
If you compare output of getfacl command before and after using setfacl command with -
b option, you can observe that there is no particular entry for user mandeep in later output.
You can also check if there are any extra permissions set through ACL using ls command.
check set acl with ls
Observe the first command output in image, there is extra “+” sign after the permissions
like -rw-rwxr–+, this indicates there are extra ACL permissions set which you can check
by getfacl command.
Using Default ACL :
The default ACL is a specific type of permission assigned to a directory, that doesn’t
change the permissions of the directory itself, but makes so that specified ACLs are set by
default on all the files created inside of it. Let’s demonstrate it : first we are going to
create a directory and assign default ACL to it by using the -d option:
$ mkdir test && setfacl -d -m u:dummy:rw test
Name of the Experiment : i) Create, Edit, Save And Exit File
ii) Edit A System File Using Vim
You can write the specified lines by passing the filename to the :w . For example,
start Vim without a filename:
$ vim
Next, enter the insert mode by pressing the i key and add desired text. Finally, press
the Esc key to return to command mode. Then type a colon ( : ) followed by w
filename . Press the Enter key. For example, save to a file named demo.txt:
:w demo.txt
OR give full path:
:w /home/vivek/projects/demo.txt
Name of the Experiment : i) Write a Script to demonstrate decision making and
loop Control
ii) Write a script demonstrate arrays
Decision Making
Control structures are structures that are used in decision making.
A condition is checked and different execution paths can be defined based on whether the condition is
true or false.
In Shell Scripts, we have two control structures:
• If Elif Else fi
• Switch cases
1. If-Else Statement
If-else Statements in Shell Scripts act as a decision statement defining alternate execution paths based on
whether the condition is true or false.
• If the condition specified is true, statements in if block are executed.
• If the condition specified is false, statements in the else block are executed.
• Unlike programming languages like C++, Java etc, Shell does not use {} to define the scope of
the if statement. Shell uses if to begin if else statement and fi to close it.
Code:
Output:
Here, the code is executed two times:
When input is anything other than "admin", code prints "Access Denied" in standard output.
When input is "admin", code prints "Access Granted" in standard output.
2. If-Elif-Else Statement
When we want to check multiple conditions and define more than two alternate paths of execution based
on decision, if elif (else if) and else statements are used.
Syntax:
if [ (Condition) ]
then
Statements...
elif [ (Condition) ]
then
Statements...
elif [ (Condition) ]
then
Statements...
...
else
Statements...
fi
Code:
Look at the above snapshot, our varname is table, list is specified under curly braces. Within the curly
braces, first two will initialize the table from 2, 20 represents maximum value of $table and last 2 shows
the increment by value 2.
Look at the above snapshot, it displays the 2's table as the output.
2) Syntax:
Syntax of for like C programming language.
Look at the above snapshot, condition1 indicates initialization, cond2 indicates condition and cond3
indicates updation.
Example for:
We have shown an example to count the number in reverse direction.
Look at the above snapshot, this is the loop script. $i will initialize with 10 and will go till 1, decrementing
with 1 value.
Declaring Arrays:
root@ubuntu:~# declare -A assoc_array
root@ubuntu:~# assoc_array[key]=value
OR
root@ubuntu:~# declare -a indexed_array
root@ubuntu:~# indexed_array[0]=value
Notice the uppercase and lowercase letter a. Uppercase A is used to declare an associative array
while lowercase a is used to declare an indexed array.
The declare keyword is used to explicitly declare arrays but you do not really need to use them.
When you’re creating an array, you can simply initialize the values based on the type of array you
want without explicitly declaring the arrays.
Now that you know how to create arrays, let’s learn how to work with arrays. Since these are
collections of data elements, we can work with loops and arrays at the same time to extract the
required data points.
Since we know that each data point is being indexed individually, we can access all the array
elements by specifying the array index as shown below:
assoc_array[element1]="Hello World"
echo ${assoc_array[element1]}
Copy
Associative Arrays In
Shell Script
Similarly, let’s access some indexed array elements. We can specify all the elements for the index
array by delimiting with spaces because the index is automatically generated for each of those
elements.
index_array=(1 2 3 4 5 6)
echo ${index_array[0]}
As you can see, the first element is automatically printed based on index 0.
for i in ${index_array[@]}
do
echo $i
done
Step 2: Now, we push the first process from the ready queue to execute its task for a fixed time, allocated
by each process that arrives in the queue.
Step 3: If the process cannot complete their task within defined time interval or slots because it is
stopped by another process that pushes from the ready queue to execute their task due to arrival time of
the next process is reached. Therefore, CPU saved the previous state of the process, which helps to
resume from the point where it is interrupted. (If the burst time of the process is left, push the process
end of the ready queue).
Step 4: Similarly, the scheduler selects another process from the ready queue to execute its tasks. When
a process finishes its task within time slots, the process will not go for further execution because the
process's burst time is finished.
Step 5: Similarly, we repeat all the steps to execute the process until the work has finished.
Completion Time: It defines the time when processes complete their execution.
Turn Around Time: It defines the time difference between the completion time (CT) and the arrival
time (AT).
Turn Around Time (TAT) = Completion Time (CT) - Arrival Time (AT)
1. Waiting Time: It defines the total time between requesting action and acquiring the resource.
Waiting Time (WT) = Turn Around Time (TAT) - Burst Time (BT)
2. Response Time: It is the time that defines at which time the system response to a process.
Output:
Name of the Experiment : i) Write a program to simulate Banker’s Algorithm for
Deadlock prevention
The reason the banker's algorithm is so titled is because it is employed in the banking sector to
determine whether or not to authorize a loan to an individual. Assume a bank has n account holders,
each of whom has an individual balance of S. When someone requests for a loan, the bank first
deducts the loan amount from the total amount of money it possesses, and only approves the loan if
the balance is more than S. It is done because the bank can simply do it if every account holder shows
up to get their money. In other words, the bank would never arrange its funds in a way that would
prevent it from meeting the demands of all of its clients. The bank would strive to maintain safety at
all times.
Let n be the number of processes in the system and m be the number of resource kinds.
Available:
o This 1-d array of size 'm' lists the number of resources of each category that are currently available.
o There are 'k' instances of the resource type if Available[j] = Rj
Max:
o The maximum demand of each process in a system is specified by a 2-d array of size 'n*m'.
o Process Pi may request a maximum of 'k' instances of resource type Rj if Max[i, j] = k.
Allocation:
o The quantity of resources of each kind currently assigned to each process is specified by a 2-d array
of size 'n*m'.
o Process is shown by Allocation[i, j] = k. Pi has been given 'k' instances of the resource type at this
time. Rj
Need:
o The remaining resource needs of each process are shown in a 2-d array of size 'n*m'.
o Process is shown by Need[i, j] = k. Right now, Pi requires "k" instances of the resource type. Rj
o Allocation[i, j] - Maximum[i, j] = Need[i, j]
The resources that are now allotted to process Pi are identified by Allocationi, while the extra
resources that process Pi could yet need in order to do its work are identified by Needi.
The safety algorithm and the resource request algorithm make up the banker's algorithm.
1. 1) Assume Work and Finish are two vectors, each with lengths of m and n.
2. Initialize: Work = Available
3. Finish[i] is false when i=1, 2, 3, 4...n
4. 2) Find an I such that both
5. a) Finish[i] = false
6. b) Needi <= Work
7. if such an I does not exist. goto step (4)
8. 3) Work = Work + Allocation[i]
9. Finish[i] = true
10. go to step (2)
11. 4) If Finish[i] = true for each and every i
12. then system is in a secure state.
Algorithm for Resource Requests
Let Requesti represent the process Pi request array. Process Pi requests k instances of resource type
Rj, which is indicated by Requesti [j] = k. The following things happen when process Pi makes a
request for resources:
1. 1) Proceed to step 2 if Requesti >= Needi; otherwise, report an error condition because the process
has made more claims than it can handle.
2. 2) Proceed to step (3) if Requesti <= Accessible; otherwise, Pi will have to wait since the resources
are not available.
3. 3) Change the state in such a way that the system appears to have given Pi the required resources:
4. Requested - Available = Available
5. Allocationi = Allocationi + Requesti
6. Needi = Needi - Requesti
Explanation:
o The processes must anticipate the maximum number of resources required as they enter the system,
which may be done in a reasonable amount of time.
o In contrast to interactive systems, this method maintains a fixed number of processes.
o A specific number of resources must be available to distribute in order for this technique to work. The
algorithm would not function if a gadget broke and went unexpectedly offline.
o The method will incur overhead costs since it must be invoked for each process when there are several
processes and resources.
Name of the Experiment : i) Write a program to simulate
page replacement algorithm[FIFO]
Page Fault
A page fault occurs when an active application tries to access a memory page that is loaded in virtual
memory but not physically in the system. Page errors occur because actual physical memory is
substantially less than virtual memory. In the event of a page fault, the operating system might have to
swap out one of the current pages for the one that is now required. Different page replacement
algorithms offer various suggestions for selecting the appropriate replacement page. All algorithms
strive to lower the number of page faults.
FIFO
The simplest algorithm for replacing pages is this one. The operating system maintains a queue for all of
the memory pages in this method, with the oldest page at the front of the queue. The first page in the
queue is chosen for removal when a page has to be replaced.
Example1: Take page reference strings 1, 3, 0, 3, 5, and 6 and three page slots as an example. All
of the spaces are initially vacant, thus when 1, 3, and 0 arrived, they were allotted to the empty
slots, which led to 3 Page Faults.
Since 3 are already in memory when it arrives, there are no page faults. Then page number 5 appears; it
cannot fit in memory, therefore it takes the position of the oldest page slot, which is 1. ->1Page Fault.
Finally, page 6 appears; however, it is likewise not in memory, thus it takes the position of the oldest
page slot, which is 3 ->1 Page Fault.
Therefore, there were 9 total page defects. Write a function to find the number of page
faults given the memory capacity (measured in the number of pages it can carry) and a
string representing the pages to be referred to.
Implementation
Let the amount of pages that memory can store serve as the capacity. Set, the current
collection of memory pages, shall be.
Experiment - 1 50 Experiment - 12 50
Experiment - 2 50 Experiment - 13 50
Experiment - 3 50 Experiment - 14 50
Experiment - 4 50 Experiment - 15 50
Experiment - 5 50 Experiment - 16 50
Experiment - 6 50 Experiment - 17 50
Experiment - 7 50 Experiment - 18 50
Experiment - 8 50 Experiment - 19 50
Experiment - 9 50 Experiment - 20 50
Experiment - 10 50 Average
50
Experiment - 11 50 Total
* LEARNING OUTCOMES:
How the Applied and Action Learning encourages Critical Thinking, Problem
Solving, Idea Generation and Skill Development etc.?
How the Applied and Action Learning encourages Leadership, Team Work,
Reflection and Decision Making Capability etc.?
1 2 3 4 5 6 7 8 9 10
LOW HIGH
➢ Books/Manuals Referred:
CAMPUSES:
Paralakhemundi Campus Bhubaneswar Campus Balangir Campus Rayagada Campus Balasore Campus Chatrapur Campus
Village Alluri Nagar Ramchandrapur Behind BSNL Office IDCO Industrial Area Gopalpur, Ramchandrapur,
P.O. – R Sitapur, Via- Uppalada P.O. – Jatni, Bhubaneswar IDCO land, Rajib Nagar Pitamahal, Rayagada P.O.-Balasore Kaliabali Chhak,
Paralakhemundi, Dist.- Gajapati Dist.- Khurda, Odisha, Dist.- Balangir, Odisha Dist.-Rayagada, Odisha Dist.-Balasore, Odisha P.O-Chatrapur, Dist.-Ganjam
Odisha, India. PIN– 761211 India, PIN– 752050 India, PIN-767001 India, PIN-765001 India, PIN-756044 Odisha, India, PIN-761020