Os 1-4
Os 1-4
Linux
installation- Steps for installing Linux Operating System Internal & External commands
in Linux.
● Other commands – tput clear, who, cal, date, bc, man, passwd, uname( with different
options).
Commands:
1.echo command: echo command in linux is used to display line of text/string that are
passed as an argument
Example:
If we want to display “welcome”. We use the following command.
echo "welcome"
2. ls Command
ls is a Linux shell command that lists directory contents of files and directories. It
provides valuable information about files, directories, and their attributes.
3. cp Command
Syntax of cp Command
cp source_file destination
cp Src_file Dest_file
4. mv stands for move. mv is used to move one or more files or directories from one place
to another in a file system like UNIX. It has two distinct functions:
(i) It renames a file or folder.
(ii) It moves a group of files to a different directory
mv intro manual/chap1
This moves the intro file to the manual/chap1 directory. The name intro is removed from the
current directory, and the same file appears as chap1 in the manual directory
5.rm:
The rm command removes the entries for a specified file, group of files, or certain select files from a
list within a directory.
rm myfile
6. cat(concatenate) command is very frequently used in Linux. It reads data from the file and
gives their content as output. It helps us to create, view, concatenate files.
Use the cat command to read each File parameter in sequence and writes it to standard output.
To display the contents of the file “notes”, type the following:
cat notes
7. clear is a standard Unix computer operating system command that is used to clear the
terminal screen
11.bc Command
bc command is used for command line calculator. It is similar to basic calculator by using
which we can do basic mathematical calculations.
12.man command in Linux is used to display the user manual of any command that we can
run on the terminal
man ls
13. passwd command changes passwords for user accounts. A normal user may only
change the password for their own account, while the superuser may change the password for
any account. passwd also changes the account or associated password validity period.
14. Uname: The command ‘uname‘ displays the information about the system.
uname [OPTIONs]
Syntax: uname -a
Output:kernal
15. grep filter searches a file for a particular pattern of characters, and displays all lines that
contain that pattern.
To search in a file named pgm.s for a pattern that contains some of the pattern-
matching characters *, ^, ?, [, ], \(, \), \{, and \}, in this case, lines starting with any
lowercase or uppercase letter, type the following:
16. egrep is a pattern searching command which belongs to the family of grep functions. It
works the same way as grep -E does.
17.fgrep filter is used to search for the fixed-character strings in a file. There can be
multiple files also to be searched. This command is useful when you need to search for
strings which contain lots of regular expression metacharacters, such as “^”, “$”, etc
Ex.No2:
● File related Commands – cat, cp, mv, rm, comm, cmp, diff, tar, umask, wc Basic File
attributes.
1.File:
file -v
2. pwd stands for Print Working Directory: It prints the path of the working directory, starting
from the root. pwd is shell built-in command(pwd) or an actual binary(/bin/pwd).
3. mkdir command in Linux allows the user to create directories (also referred to as folders
in some operating systems ). This command can create multiple directories at once as well as
set the permissions for the directories
4. rmdir command is used remove empty directories from the filesystem in Linux. The rmdir
command removes each and every directory specified in the command line only if these
directories are empty.
Syntax:
7. comm : comm compare two sorted files line by line and write to standard
output; the lines that are common and the lines that are unique.
Syntax :
$comm [OPTION]... FILE1 FILE2
8. cmp command in Linux/UNIX is used to compare the two files byte by byte and helps
you to find out whether the two files are identical or not.
9. diff stands for difference. The diff command is a versatile utility that is pre-installed on
most Linux distributions. Its primary purpose is to compare the contents of two files and
display the differences between them.
10. tar: The Linux ‘tar’ stands for tape archive, which is used to create Archive and extract
the Archive files. tar command in Linux is one of the important commands that provides
archiving functionality in Linux.
11. umask: The umask command in Linux is used to set default permissions for files or
directories the user creates.
$umask
Output: 0002
• first 0 as of now. the next three digits are 0 0 2.
• Each digit here is for different classes of users, there are a total of 3 classes of users in
Linux,
• The owner
• group members
• everyone else
12.wc: wc stands for word count. As the name implies, it is mainly used for counting
purpose.
• It is used to find out number of lines, word count, byte and characters
count in the files specified in the file arguments.
13. Listing seven attributes of a file : ls
The -l flag allows you to get a list of a Linux directory's content with a detailed description of each
entry. Following information are included in the output:
output:
15.chown:
The `chown` command, short for “change owner,” is a powerful tool that allows users to
change the owner of files and directories.
Syntax:
● Changing process priority, scheduling process (Usage of sleep and wait commands)
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
pid_t pid, mypid, myppid;
pid = getpid();
printf("Before fork: Process id is %d\n", pid);
pid = fork();
if (pid < 0)
{
perror("fork() failure\n");
return 1;
}
// Child process
if (pid == 0)
{
printf("This is child process\n");
mypid = getpid();
myppid = getppid();
printf("Process id is %d and PPID is %d\n", mypid, myppid);
}
else
{ // Parent process
sleep(2);
printf("This is parent process\n");
mypid = getpid();
myppid = getppid();
printf("Process id is %d and PPID is %d\n", mypid, myppid);
printf("Newly created process id or child pid is %d\n", pid);
}
return 0;
}
OUTPUT:
4. Design, Develop and Implementation of CPU scheduling by using
a. FCFS
b. Priority
DESCRIPTION
A) FCFS CPU SCHEDULING ALGORITHM: For FCFS scheduling algorithm, read the
number of processes/jobs in the system, their CPU burst times. The scheduling is performed
on the basis of arrival time of the processes irrespective of their other parameters. Each process
will be executed according to its arrival time. Calculate the waiting time and turnaround time
of each of the processes accordingly.
Program:
FCFS Scheduling:
#include<stdio.h>
#include<conio.h>
main()
{
int bt[20], wt[20], tat[20], i, n;
float wtavg, tatavg;
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);
}
Output:
B) PRIORITY CPU SCHEDULING ALGORITHM: For priority scheduling algorithm,
read the number of processes/jobs in the system, their CPU burst times, and the priorities.
Arrange all the jobs in order with respect to their priorities. There may be two jobs in queue
with the same priority, and then FCFS approach is to be performed. Each process will be
executed according to its priority. Calculate the waiting time and turnaround time of each of
the processes accordingly.