OSLabManual 1 3
OSLabManual 1 3
Aim:
To boot Linux Operating System.
Algorithm:
Press the power button on your system, and after few moments you see the Linux login prompt. From
the time you press the power button until the Linux login prompt appears, the following sequence
occurs. The following are the 6 high level stages of a typical Linux boot process.
Power On
Kernel Init
Init
Kernel executes runlevel programs
Login Process
Step 1 : BIOS
● BIOS stands for Basic Input/Output System ● Performs some system integrity
checks
● Searches, loads, and executes the boot loader program.
● It looks for boot loader in floppy, CD-ROMs, or hard drive. You can press a key (typically F12 or F2,
but it depends on your system) during the BIOS startup to change the boot sequence.
● Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
● So, in simple terms BIOS loads and executes the MBR boot loader.
Step 2. MBR
● MBR stands for Master Boot Record.
● It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda ● MBR is less than 512
bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info
in next 64 bytes 3) mbr validation check in last 2 bytes. ● It contains information about GRUB (or LILO in
old systems).
● So, in simple terms MBR loads and executes the GRUB boot loader. Step 3.
GRUB
● GRUB stands for Grand Unified Bootloader.
● If you have multiple kernel images installed on your system, you can choose which one to be executed.
● GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default
kernel image as specified in the grub configuration file.
● GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).
● Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample
grub.conf of CentOS.
#boot=/dev/sda default=0 timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz hiddenmenu title
CentOS(2.6.18-194.el5PAE) root(hd0,0)
kernel/boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/ initrd /boot/initrd-2.6.18-
194.el5PAE.img
● As you notice from the above info, it contains kernel and initrd image. ● So, in simple
terms GRUB just loads and executes Kernel and initrd images.
Step 4. Kernel
● Mounts the root file system as specified in the “root=” in grub.conf ● Kernel
executes the /sbin/init program
● Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps
-ef | grep init’ and check the pid.
● initrd stands for Initial RAM Disk.
● initrd is used by kernel as temporary root file system until kernel is booted and the real root file system
is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive
partitions, and other hardware.
Step 5. init
● Looks at the /etc/inittab file to decide the Linux run level.
● Following are the available run levels
1 – halt
2 – Single user mode
3 –Multiuser,without NFS
4 – Full multiuser mode
5 – unused
6 – X11
7 – reboot
● init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
● Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level ● If you want to
get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means,
probably you might not do that.
● Typically, you would set the default run level to either 3 or 5.
Login Process
1. Users enter their username and password
2. The operating system confirms your name and password.
3. A "shell" is created for you based on your entry in the "/etc/passwd" file 4. You are
"placed" in your "home"directory.
5. Start-up information is read from the file named "/etc/profile". This file is known as the system login
file. When every user logs in, they read the information in this file. 6. Additional information is read from
the file named ".profile" that is located in your "home" directory. This file is known as your personal login
file.
Result:
Hence the Linux Operating system was booted successfully and the execution of basic
linux commands in JS Linux online compiler was successfully completed
Ex. No. 1B BASIC LINUX COMMANDS Date:
Aim:
To execute basic linux commands in JS Linux online compiler
Algorithm:
Basics
1. echo SRM
→ to display the string SRM
2. clear → to clear the screen
3. date → to display the current date and time
cal 6 2003
4. cal 2003 → to display the calendar for the year 2003 → to display
the calendar for the June-2003 5. passwd → to change password
e) Piping
Syntax : Command1 | command2
Output of the command1 is transferred to the command2 as input. Finally output of the command2
will be displayed on the monitor.
ex. cat f1 | more →list the contents of file f1 screen by screen head –6 f1 |tail –2 →prints the 5th & 6th
lines of the file f1. cal 2015 | wc -c → counts the number of characters in the displaying the cal g)
Environment variables
1. echo $HOME
→ display the path of the home directory
2. echo $PS1 → display the prompt string $
3. echo $PS2 → display the second prompt string ( > symbol by default ) 4. echo $LOGNAME
→ login name
5. echo $PATH
→ List of pathname where the OS searches for an executable file
h) File Permission
-- chmod command is used to change the access permission of a file. Method-1
Syntax : chmod [ugo] [+/-] [ rwxa ] filename
u : user, g : group, o : others
+ : Add permission - : Remove the permission
r : read, w : write, x : execute, a : all permissions
ex. chmod ug+rw f1
adding ‘read & write’ permissions of file f1 to both user and group members. Method-2
Syntax : chmod octnum file1
The 3 digit octal number represents as follows
● first digit -- file permissions for the user
● second digit -- file permissions for the group
● third digit -- file permissions for others
Each digit is specified as the sum of following
4 – read permission,2 – write permission, 1 – execute ex. chmod 754 f1 it change the file
permission for the file as follows
● read, write & execute permissions for the user ie; 4+2+1 = 7 ● read, & execute permissions
for the group members ie; 4+0+1 = 5 ● only read permission for others ie; 4+0+0 = 4
Result:
The execution of basic linux commands in JS Linux online compiler was successfully completed
and the output was verified.
Ex. No. 2A LINUX FILE SYSTEM Date:
Aim:
To execute file system commands in JS Linux through Online JS linux compiler.
Algorithm:
Linux File System
Linux File System or any file system generally is a layer which is under the operating system that
handles the positioning of your data on the storage, without it; the system cannot knows which file starts
from where and ends where.
Linux offers many file systems types like:
● Ext: an old one and no longer used due to limitations.
● Ext2: first Linux file system that allows 2 terabytes of data allowed. ● Ext3: came from Ext2, but with
upgrades and backward compatibility. ● Ext4: faster and allow large files with significant speed.(Best Linux
File System) It is a very
good option for SSD disks and you notice when you try to install any Linux distro that this one is the
default file system that Linux suggests.
● JFS: old file system made by IBM. It works very well with small and big files, but it failed and files
corrupted after long time use, reports say.
● XFS: old file system and works slowly with small files.
● Btrfs: made by Oracle. It is not stable as Ext in some distros, but you can say that it is a replacement
for it if you have to. It has a good performance.
Aim:
To study the various editors and filtering commands of linux OS and execute them in JS Linux
Algorithm:
VI EDITOR
vi fname →to open the file fname
a) Inserting Text
i insert text before the cursor
a append text after the cursor
I insert text at the beginning of the line
A append text to the end of the line
r replace character under the cursor with the next character typed
R Overwrite characters until the end of the line
o (small o) open new line after the current line to type text
O (capital O) open new line before the current line to type text
b) Cursor movements
h left
j down
k up
l right
(The arrow keys usually work also)
^F forward one screen
^B back one screen
^D down half screen
^U up half screen
(^ indicates control key; case does not matter)
0 (zero) beginning of line
$ end of line
d) Saving files
:w to save & resume editing (write & resume)
:wq to save & exit (write & quit)
:q! quit without save
e) Cut, Copy and Paste
yy copies current line
(n) yy copies (n) lines from the current line. ex. 4yy copies 4 lines.
p paste deleted or yanked (copied) lines after the cursor
FILTERS
2. paste : Paste files vertically. That is nth line of first file and nth line of second file are pasted as
the n line of result
th
of a sorted file
Result:
Hence the editors and filtering commands were successfully executed and the output was verified
using JS Linux .
Ex. No. 3A COMPILATION OF C PROGRAM Date :
Aim:
To compile a C program by file creation in Linux OS and execute it using appropriate linux commands.
Algorithm:
Compilation of C Program
Step 1 : Open the terminal and edit your program using vi editor/gedit editor and save
withextension “.c”
Ex. vi test.c
(or) gedit text.c
Step 3 : Correct the errors if any and run the program Ex. ./a.out
(or)
./test
Optional Step : In order to avoid ./ prefix each time a program is to be executed, insert thefollowing
as the last line in the file .profile export PATH=.:$PATH This Step needs only to be done once.
Break points set up at line number 10. We can have any number of break
Step 5 : Print variable to get the intermediate values of the variables at break point Ex. (gdb) p i 🡪
Prints the value of the variable ‘i'
Step 6 : Continue or stepping over the program using the following gdb
commandsc 🡪 continue till the next break
n🡪Execute the next line. Treats function as single statement
s 🡪Similar to ‘n’ but executes function statements line
by linel 🡪List the program statements
Step 7 : Quit the debugger (gdb) q
Result: Hence the c program was successfully compiled and the output was verified.
Ex. No. 3B PROCESS CREATION Date :
Aim:
To create a process and check how the child and the parent processes work usingvarious
commands in JS linux .
Algorithm:
Process creation
1. fork() causes the UNIX system to create a new process, called the "child process", with a new
process ID.
2. The contents of the child process are identical to the contents of the parentprocess.
Virtual fork vfork() function is similar to fork but both processes shares the same address space.
Q3. Write the output the following program and brief your understanding #include <stdio.h>
#include<unistd.h>
int main()
{ int a=5,b=10,pid;
printf("Before fork a=%d b=%d \n",a,b);
pid=fork(); if(pid==0)
{ a=a+1;
b=b+1;
printf("In child a=%d b=%d \n",a,b);
}
else
{ sleep(1);
a=a-1; b=b-1;
printf("In Parent a=%d b=%d \n",a,b);
} return 0;
}
Output :
Q4. Rewrite the program in Q1 using vfork() and write the output
#include <stdio.h>
#include<unistd.h>
int main()
{ int a=5,b=10,pid;
printf("Before fork a=%d b=%d \n",a,b);
pid=vfork();
if(pid==0)
{ a=a+1;
b=b+1;
printf("In child a=%d b=%d \n",a,b);
}
else
{ sleep(1); a=a
1; b=b-1;
printf("In Parent a=%d b=%d \n",a,b);
} return 0;
}
The address space of child is used by parent, hence have a problem in accessing variable
Q5. Calculate the number of times the text “SRMIST” is printed and write your
inference in this.
#include <stdio.h>
#include<unistd.h>
int main()
{ fork(); fork(); fork();
printf(“SRMIST\n”); return
0;
}
Output :
Q7. How many child processes are created for the following code?
Q8. Write a program to print the Child process ID and Parent process ID in both Child and
Parent processes
Output:
Q9. How many child processes are created for the following code? Brief your
inference#include <stdio.h>
#include<unistd.h>
int main()
{ fork();
fork()&&fork()||fork();
fork(); printf(“Yes”);
return 0;
Output :
Output
Result :
The programs given are executed successfully.