0% found this document useful (0 votes)
29 views16 pages

Os 1-4

The document provides an overview of Linux commands and their functionalities, covering internal and external commands, file and directory management, and process management. It includes detailed descriptions of commands such as echo, ls, cp, mv, rm, and others, along with examples of usage. Additionally, it discusses CPU scheduling algorithms like FCFS and Priority, including sample code for implementation.

Uploaded by

Shashank S
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)
29 views16 pages

Os 1-4

The document provides an overview of Linux commands and their functionalities, covering internal and external commands, file and directory management, and process management. It includes detailed descriptions of commands such as echo, ls, cp, mv, rm, and others, along with examples of usage. Additionally, it discusses CPU scheduling algorithms like FCFS and Priority, including sample code for implementation.

Uploaded by

Shashank S
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/ 16

Ex.No 1: 1. Introduction- Linux Architecture- Shell, Kernel, System calls.

Linux
installation- Steps for installing Linux Operating System Internal & External commands
in Linux.

● Internal commands- echo, type, etc.

● External commands- ls, cp, mv, rm, cat, etc

● Other commands – tput clear, who, cal, date, bc, man, passwd, uname( with different
options).

● Expressions & search patterns.(dot operator), *, A, +, ?, grep, egrep, fgrep

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.

ls-l is used To show long listing information about the file/directory.

3. cp Command

cp: copy the contents of one file to another

Syntax of cp Command

cp source_file destination
cp Src_file Dest_file

• If `Dest_file` does not exist, it is created.


• If `Dest_file` already exists, it is overwritten without any warning

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.

To delete the file named myfile, type the following:

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

8. who command is used to find out the following information :


1. Login name of the users
2. Terminal line numbers
3. Login time of the users into the system
4. The remote host name of the user
9.cal: displays the calendar of the current month.

10.date: displays current date.

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

The basic syntax of the “man” command is as follows:


man [option] [command]

to view the manual for the “ls” command:

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.

the basic syntax of uname command is as follows:

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:

grep "^[a-zA-Z]" pgm.s


This displays all lines in the pgm.s file that begin with a letter.
To display all lines in a file named sort.c that do not match a particular pattern, type
the following:

grep -v bubble sort.c

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:

2. Working with files & directories.

● Know the categories of files.

● Directory related Commands – pwd, mkdir, rmdir, cd, ls

● Manipulating Absolute paths and Relative paths using cd command.

● File related Commands – cat, cp, mv, rm, comm, cmp, diff, tar, umask, wc Basic File
attributes.

● Listing seven attributes of a file : ls and its options

● File Permissions: Absolute and Relative permissions

● Manipulating File permissions using chmod command

● Manipulating File Ownership using chown command

● Manipulating Hardlink and Softlink using ln command

1.File:

file command examples to determine a file type in Linux.


To find out file types we can use the file command.
Syntax: file [OPTION…] [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.

5. cd command in linux known as change directory command. It is used to change current


working directory.

6. .rm: remove a particular file.

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:

1. File and folder permissions


2. Number of links
3. Content owner
4. Group owner
5. Content size
6. File name
7. Last-modified date and time

output:

14. chmod command is used to change the access mode of a file.


If we want to revert the changes to “rw-r–r–” (read and write permission for
owner, read-only permission for group and others), according to this our octal
value would be “644” (read = 4, write=2).

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:

the ownership of `file1.txt` is changed

16. Hardlink & SoftLink


Each hard-linked file is assigned the same Inode value as the original, therefore they
reference the same physical file location.
if we have a file a.txt. If we create a hard link to the file and then delete the file, we can still
access the file using hard link. But if we create a soft link of the file and then delete the file,
we can’t access the file through soft link and soft link becomes dangling.
Hardlink: Syntax:
Softlink: Syntax

Ex.No 3. Process Management commands.

● Process creation, status, Identifying process, ps -f &its options,

● Running process in background, Job control, and Process termination.

● 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.

PRIORITY CPU SCHEDULING


#include<stdio.h>
#include<conio.h>
struct process
{
int pid;
int bt;
int wt;
int tt;
int prior;
}
p[10],temp;
int main()
{
int i,j,n,totwt,tottt,arg1,arg2;
clrscr();
printf("enter the number of process");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
p[i].pid=i;
printf("enter the burst time");
scanf("%d",&p[i].bt);
printf("\n enter the priority");
scanf("%d",&p[i].prior);
}
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if(p[i].prior>p[j].prior)
{
temp.pid=p[i].pid;
p[i].pid=p[j].pid;
p[j].pid=temp.pid;
temp.bt=p[i].bt;
p[i].bt=p[j].bt;
p[j].bt=temp.bt;
temp.prior=p[i].prior;
p[i].prior=p[j].prior;
p[j].prior=temp.prior;
}
}
}
p[i].wt=0;
p[1].tt=p[1].bt+p[1].wt;
i=2;
while(i<=n)
{
p[i].wt=p[i-1].bt+p[i-1].wt;
p[i].tt=p[i].bt+p[i].wt;
i++;
}
i=1;
totwt=tottt=0;
printf("\n process to \t bt \t wt \t tt");
while(i<=n)
{
printf("\n%d\t %d\t %d\t %d\t",p[i].pid,p[i].bt,p[i].wt,p[i].tt);
totwt=p[i].wt+totwt;
tottt=p[i].tt+tottt;
i++;
}
arg1=totwt/n;
arg2=tottt/n;
printf("\n arg1=%d \t arg2=%d\t",arg1,arg2);
getch();
return 0;
}
Output:

You might also like